Question: How to manipulate a table filter based on user profile?

  • 1
  • Question
  • Updated 11 months ago
  • Answered
i have a table that displays opportunities with a table filter.  on load I'd like to set the table filter dynamically based on the user's profile.

Just wanted to  get some implementation ideas here but I'm thinking the following...
  • On load snippet
  • based on profile set the model's condition
  • but how do I manipulate the selected value in the table filter?
Photo of Jaime

Jaime

  • 1,220 Points 1k badge 2x thumb

Posted 11 months ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Jaime,

A filter can take a model as 'Source' for values to show and filter by.  You can also use a Snippet to set the values for the filter.

Here is a page that looks up the Running User's StateCode and uses it to filter Accounts by ShippingStateCode.  This model is then used for the table to filter Opportunities by Account.  This is all done 'declaratively'.  Note that you will need to have State and Country pick lists enabled to see this in action.  You can switch to use the 'State' field on the user record instead.

Thanks,

Bill

<skuidpage unsavedchangeswarning="" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Opportunity">
    <models>
        <model id="CurrentUser" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="User">
            <fields>
                <field id="Name"/>
                <field id="Id"/>
                <field id="StateCode"/>
            </fields>
            <conditions>
                <condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
            </conditions>
            <actions/>
        </model>
        <model id="AccountFilter" limit="100" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="Account">
            <fields>
                <field id="Name"/>
                <field id="Id"/>
                <field id="ShippingStateCode"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="ShippingStateCode" operator="=" state="" model="CurrentUser" enclosevalueinquotes="true" mergefield="StateCode" novaluebehavior="noquery"/>
            </conditions>
            <actions/>
        </model>
        <model id="Opportunity" limit="100" query="true" createrowifnonefound="false" sobject="Opportunity" type="" datasource="salesforce">
            <fields>
                <field id="Name"/>
                <field id="CreatedDate"/>
                <field id="NewField" uionly="true" displaytype="TEXT" label="Model UI"/>
                <field id="AccountId"/>
                <field id="Account.Name"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="AccountId" fieldtargetobjects="Account" state="filterableoff" inactive="true" name="AccountId"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <pagetitle model="Opportunity" uniqueid="sk-3Bsoue-80">
            <maintitle>
                <template>{{Model.labelPlural}}</template>
            </maintitle>
            <subtitle>
                <template>Home</template>
            </subtitle>
            <actions>
                <action type="savecancel" uniqueid="sk-1sTJR2-232"/>
            </actions>
        </pagetitle>
        <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Opportunity" mode="read" uniqueid="sk-3Bsoue-81">
            <fields>
                <field id="Name" allowordering="true" uniqueid="sk-1sTJRE-238"/>
                <field id="AccountId" hideable="true" uniqueid="fi-1sTSWt-298" valuehalign="" type=""/>
                <field id="CreatedDate" allowordering="true" uniqueid="sk-1sTJRG-241"/>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
            <filters>
                <filter type="select" filteroffoptionlabel="Any Account" createfilteroffoption="true" affectcookies="false" autocompthreshold="25" conditionsource="manual" filtermethod="server" labelmode="no" condition="AccountId">
                    <sources>
                        <source type="model" effectsbehavior="justdefault" model="AccountFilter">
                            <labeltemplate>{{{Name}}}</labeltemplate>
                            <valuetemplate>{{Id}}</valuetemplate>
                        </source>
                    </sources>
                </filter>
            </filters>
        </skootable>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript/>
        <actionsequences uniqueid="sk-1sTSWe-293"/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of Jaime

Jaime

  • 1,220 Points 1k badge 2x thumb
thank you  Bill for the quick response...very interesting I think I'll still need a snippet though because in my case the filter is on record type.  So I still want to  provide the ability to filter on any of the opportunities record type it's just that for some user profiles I need to set the filter to record type y as opposed to other profiles would by default see record type x as selected.

other profiles see
x(selected)
y
z

specifc profiles
x
y(selected)
z
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Jaime,

I think you should add a Custom Setting for your filtering.  The Custom Setting can apply at the Profile level.  You can store the RecordtypeId for the Opportunity record type that you want that Profile to 'see'.

On your Opportunity model, add 1 condition for your RecordType filter and another condition for Recordtype based on the Custom Setting.  When your page loads, you can check the user's custom setting.  If you find an Id, you can set both conditions to the same RecordType to limit what Opportunities that user can see.  If the user changes the filter for RecordType, they will see no opportunities.

If you are using Skuid 11 (Millau), then you can do this declaratively using an Action Sequence that triggers when the page is rendered.

Thanks,

Bill