Problem in selecting the multiselect picklist values from javascript snippet based on the another field condition

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I had a requirement to update the Mutlipicklist value based on other picklist value.
scenario :condition (1) If picklist1 = x value selected then it should update the Multiselectpicklist value with x,y as default and user should be able to select other values ex : z also along with x,y. condition ( 2) : user should be able to deselect the default values if they are not intrested.)
Photo of sudeer

sudeer

  • 70 Points
  • confused

Posted 2 years ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Sudeer,

If you're in a new-enough version of Skuid, you can use a model action with the Branch feature to get this working. 

In my test page, I have a model on the Account object. It has a model action set to run some actions whenever the Industry field is updated. That looks like this:



The actions it runs look like this:



(Edited to include this screenshot of the action itself):


It will evaluate the value of Industry and run a different set of actions, depending on what the value is. I'd recommend reading our documentation on the Action Framework, specifically for the Branch action, to help you understand this. 

Below is the XML for my test page. It uses a custom field, "TestMulti__c" on the Account object, so you might need to replace the field name or model if you want to use the code. Or, you may be able to set your solution up by following the screenshots above. 

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
<models>
<model id="acc" limit="1" query="false" createrowifnonefound="true" datasource="salesforce" type="" sobject="Account">
<fields>
<field id="Industry"/>
<field id="Name"/>
<field id="TestMulti__c"/>
</fields>
<conditions/>
<actions>
<action>
<actions>
<action type="branch" model="acc" label="Industry is Consulting">
<formula>{{Industry}} == "Consulting"</formula>
<iftrueactions>
<action type="updateRow" fieldmodel="acc" affectedrows="context" field="TestMulti__c" enclosevalueinquotes="true" value="A;B"/>
</iftrueactions>
</action>
<action type="branch" label="Industry is Government" model="acc">
<formula>{{Industry}} == "Government"</formula>
<iftrueactions>
<action type="updateRow" fieldmodel="acc" affectedrows="context" field="TestMulti__c" enclosevalueinquotes="true" value="C;D"/>
</iftrueactions>
</action>
</actions>
<events>
<event>row.updated</event>
</events>
<fields>
<field>Industry</field>
</fields>
</action>
</actions>
</model>
</models>
<components>
<basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="acc" buttonposition="" uniqueid="sk-1YAtfi-125" mode="edit" layout="">
<columns>
<column width="50%">
<sections>
<section title="Section A" collapsible="no">
<fields>
<field id="Name" valuehalign="" type=""/>
<field id="Industry" valuehalign="" type=""/>
</fields>
</section>
</sections>
</column>
<column width="50%">
<sections>
<section title="Section B" collapsible="no">
<fields>
<field id="TestMulti__c" selectedlist="3" valuehalign="" type="CHECKBOXES"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
</components>
<resources>
<labels/>
<javascript/>
<css/>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>
(Edited)