Snippets

Roman Melnik Skuid Sample Page: Single-Step Solution for Mass Creating Related Records on Junction Objects

Created by Roman Melnik last modified
<skuidpage showsidebar="false" showheader="true" tabtooverride="Product2" unsavedchangeswarning="" personalizationmode="server">
   <models>
      <model id="Product2Data" limit="25" query="true" createrowifnonefound="false" sobject="Product2" orderby="Name ASC" adapter="salesforce" type="" service="salesforce">
         <fields>
            <field id="Name"/>
            <field id="CreatedDate"/>
            <field id="PricebookEntries" type="childRelationship">
               <fields>
                  <field id="UnitPrice"/>
               </fields>
               <conditions>
                  <condition enclosevalueinquotes="false" field="Pricebook2.IsStandard" value="true"/>
               </conditions>
            </field>
            <field id="IsActive"/>
            <field id="Description"/>
            <field id="ProductCode"/>
            <field id="Family"/>
            
            
            
         <field id="UiOnlyMultiselect" uionly="true" displaytype="MULTIPICKLIST" label="Price Books">
<picklistentries>
    <entry value="default" label="default"/>
</picklistentries>
</field>
<field id="Id"/>
</fields>
         <conditions>
            <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="Family" state="filterableoff" inactive="true" name="ProductFamily"/>
            <condition type="fieldvalue" value="true" enclosevalueinquotes="false" field="IsActive" state="filterableoff" inactive="true" name="JustActiveProducts"/>
         </conditions>
      <actions>
<action>
    <actions>
        <action type="createRow" model="Pricebook_Entries" appendorprepend="prepend" defaultmodefornewitems="edit">
            <defaults>
                <default type="fieldvalue" field="Product2Id" enclosevalueinquotes="true" value="{{$Model.Product2Data.data.0.Id}}"/>
                <default type="fieldvalue" field="Pricebook2Id" enclosevalueinquotes="true" value="{{$Model.DefaultValue_StandardPricebook.data.0.Id}}"/>
            </defaults>
        </action>
    </actions>
    <events>
        <event>row.created</event>
    </events>
</action>
</actions>
</model>
<model id="Pricebook_Entries" limit="25" query="false" createrowifnonefound="false" adapter="salesforce" type="" sobject="PricebookEntry" doclone="">
    <fields>
        <field id="Id"/>
        <field id="Pricebook2Id"/>
        <field id="Pricebook2.Name"/>
        <field id="Product2Id"/>
        <field id="Product2.Name"/>
        <field id="UnitPrice" overridemetadata="true" ogdisplaytype="CURRENCY" displaytype="CURRENCY" precision="" scale="" defaultValue="0.0"/>
    </fields>
    <conditions>
        <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="Pricebook2Id" state="filterableoff" inactive="true" name="Price_Book__c"/>
    </conditions>
    <actions/>
</model>
<model id="Pricebooks" limit="25" query="true" createrowifnonefound="false" orderby="Name ASC" sobject="Pricebook2" adapter="salesforce" type="" doclone="">
         <fields>
            <field id="Name"/>
            <field id="IsActive"/>
            <field id="IsStandard"/>
         <field id="Id"/>
</fields>
         <conditions/>
      <actions/>
</model>
      
      <model id="Assets" limit="10" query="true" createrowifnonefound="false" orderby="SystemModstamp DESC" sobject="Asset" adapter="salesforce" type="">
         <fields>
            <field id="Id"/>
            <field id="Name"/>
            <field id="SerialNumber"/>
            <field id="InstallDate"/>
            <field id="Account.Name"/>
            <field id="Contact.Id"/>
            <field id="Product2.Name"/>
         </fields>
         <conditions/>
      <actions/>
</model>
   <model id="DefaultValue_StandardPricebook" limit="1" query="true" createrowifnonefound="false" adapter="salesforce" type="" sobject="Pricebook2">
<fields>
    <field id="Id"/>
    <field id="Name"/>
    <field id="IsStandard"/>
</fields>
<conditions>
    <condition type="fieldvalue" value="true" enclosevalueinquotes="false" field="IsStandard"/>
</conditions>
<actions/>
</model>
</models>
   <components>
      <pagetitle model="Product2Data" uniqueid="sk-1M9jTC-116">
         <maintitle>
            <template>{{Model.LabelPlural}}</template>
         </maintitle>
         <subtitle>
            <template>Home</template>
         </subtitle>
         <actions>
            <action type="redirect" label="Manage Price Books" url="/pbk/priceBookList.jsp" icon="ui-silk-book-edit"/>
         </actions>
      </pagetitle>
      <tabset uniqueid="sk-1M9jTC-117">
         <tabs>
            <tab name="Products" icon="ui-silk-cart">
               <components>
                  <skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="false" model="Product2Data" mode="read" uniqueid="sk-1M9jTC-118">
                     <fields>
                        <field id="Name" allowordering="true"/>
                        <field id="ProductCode"/>
                        <field id="Description"/>
                        <field id="Family" valuehalign="" type=""/>
                        <field id="IsActive"/>
                        <field id="CreatedDate" allowordering="true"/>
                        <field type="COMBO" valuehalign="">
                           <label>Standard Price</label>
                           <template>{{#PricebookEntries.records}}{{UnitPrice}}{{/PricebookEntries.records}}</template>
                        </field>
                     <field id="Id" valuehalign="" type=""/>
</fields>
                     <rowactions>
                        <action type="edit"/>
                        <action type="delete"/>
                     </rowactions>
                     <massactions usefirstitemasdefault="true">
                        <action type="massupdate"/>
                        <action type="massdelete"/>
                        <action type="redirect" url="/setup/own/massdelete.jsp?ftype=Product2" label="Mass Delete Products" icon="ui-silk-delete" window="self"/>
                     </massactions>
                     <views>
                        <view type="standard"/>
                        <view type="photo" defaultphoto="org" photofield="skuidcrm__Product_Image__c" descriptionfield="Name" onclickurl="/{{Id}}"/>
                     </views>
                     <filters>
                        <filter type="select" filteroffoptionlabel="Any Product Family" createfilteroffoption="true" affectcookies="true" autocompthreshold="25" condition="ProductFamily">
                           <sources>
                              <source type="metadata" effectsbehavior="justdefault" prefix="Family: "/>
                           </sources>
                        </filter>
                        <filter type="toggle" filteroffoptionlabel="New Filter" createfilteroffoption="true" affectcookies="true" autocompthreshold="25" label="Just Active Products">
                           <effects>
                              <effect action="activate" value="" condition="JustActiveProducts"/>
                           </effects>
                        </filter>
                     </filters>
                  <actions defaultlabel="Global Actions" defaulticon="sk-icon-magic" usefirstitemasdefault="true">
<action type="multi" label="Add Product w/ Related Pricebooks" icon="sk-icon-magic">
    <actions>
        <action type="blockUI" message="Loading..."/>
        <action type="createRow" model="Product2Data" appendorprepend="prepend" defaultmodefornewitems="edit">
            <defaults>
                <default type="fieldvalue" field="IsActive" enclosevalueinquotes="false" value="true"/>
            </defaults>
        </action>
        <action type="requeryModels" model="Pricebooks" behavior="standard">
            <models>
                <model>Pricebooks</model>
            </models>
        </action>
        <action type="showPopup">
            <popup title="New Popup" width="50%">
                <components>
                    <pagetitle model="Product2Data" uniqueid="sk-1MEqNp-310">
                        <actions>
                            <action type="multi" label="Save" icon="sk-icon-save">
                                <actions>
                                    <action type="blockUI" message="Saving..."/>
                                    <action type="custom" snippet="createRelatedRecords"/>
                                    <action type="save">
                                        <models>
                                            <model>Product2Data</model>
                                            <model>Pricebook_Entries</model>
                                        </models>
                                        <onerroractions>
                                            <action type="blockUI" message="There was an error" timeout="3000"/>
                                        </onerroractions>
                                    </action>
                                    <action type="requeryModel" behavior="standard" model="Product2Data"/>
                                    <action type="closeTopmostPopup"/>
                                    <action type="unblockUI"/>
                                </actions>
                            </action>
                            <action type="multi" label="Cancel" icon="sk-icon-cancel">
                                <actions>
                                    <action type="blockUI" message="Cancelling..."/>
                                    <action type="cancel">
                                        <models>
                                            <model>Product2Data</model>
                                        </models>
                                    </action>
                                    <action type="closeTopmostPopup"/>
                                    <action type="unblockUI"/>
                                </actions>
                            </action>
                        </actions>
                        <conditions>
                            <condition type="contextrow" field="Id" mergefield="Id" operator="="/>
                        </conditions>
                    </pagetitle>
                    <skootable showconditions="true" showsavecancel="false" showerrorsinline="true" searchmethod="server" searchbox="false" showexportbuttons="false" pagesize="10" createrecords="false" model="Product2Data" buttonposition="" mode="edit" uniqueid="sk-1MDnmv-202" instantfilters="true" emptysearchbehavior="query">
                        <fields>
                            <field id="Name" valuehalign="" type="" columnwidth="30%"/>
                            <field id="UiOnlyMultiselect" valuehalign="" type="CUSTOM" snippet="multiselectPicklistRenderer" columnwidth="70%"/>
                            <field id="Id" valuehalign="" type=""/>
                        </fields>
                        <rowactions>
                            <action type="edit"/>
                        </rowactions>
                        <massactions usefirstitemasdefault="true"/>
                        <views>
                            <view type="standard"/>
                        </views>
                        <conditions>
                            <condition type="contextrow" field="Id" mergefield="Id" operator="="/>
                        </conditions>
                        <searchfields/>
                    </skootable>
                </components>
            </popup>
        </action>
        <action type="unblockUI"/>
    </actions>
    <hotkeys/>
</action>
</actions>
</skootable>
               </components>
            </tab>
            <tab name="Pricebooks" icon="ui-silk-report">
               <components>
                  <skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Pricebooks" mode="read" uniqueid="sk-1M9jTC-119">
                     <fields>
                        <field id="Name" valuehalign="" type=""/>
                        <field id="IsActive"/>
                        <field id="IsStandard" type="" valuehalign=""/>
                     </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/>
                  </skootable>
               </components>
            </tab>
            <tab name="Assets" icon="ui-silk-coins">
               <components>
                  <skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Assets" mode="read" uniqueid="sk-1M9jTC-120">
                     <fields>
                        <field id="Id"/>
                        <field id="Name"/>
                        <field id="SerialNumber"/>
                        <field id="InstallDate"/>
                        <field id="Account.Name"/>
                        <field id="Contact.Id"/>
                        <field id="Product2.Name"/>
                     </fields>
                     <rowactions>
                        <action type="edit"/>
                        <action type="delete"/>
                     </rowactions>
                     <massactions usefirstitemasdefault="true">
                        <action type="massupdate"/>
                        <action type="massdelete"/>
                     </massactions>
                     <views>
                        <view type="standard"/>
                     </views>
                  </skootable>
               </components>
            </tab>
         </tabs>
      </tabset>
   </components>
   <resources>
      <labels/>
      <css/>
      <javascript>
<jsitem location="inlinesnippet" name="multiselectPicklistRenderer" cachelocation="false">var field = arguments[0], 
    row = field.row,
    
    // set the render condition
    value = skuid.utils.decodeHTML(arguments[1]),
    metadata = field.metadata,
    element = field.item.element,
    $ = skuid.$,
    pricebookModel = skuid.$M('Pricebooks');

if (field.mode =='edit'){

//create an empty array for picklist entries
var picklistEntries = [];

// creates a picklist entry for each row in your Model. 
// note defaultValue doesn't matter, the first one will be default
$.each(pricebookModel.data, function(i, row){
    picklistEntries.push({
        value: row.Id,
        label: row.Name,
        active: true,
        defaultValue: false
    });i;
});
    
    field.metadata.picklistEntries = picklistEntries;

// render the field as a multipicklist
    skuid.ui.fieldRenderers.MULTIPICKLIST[field.mode](field,value);
} 

else{
    
    //use the default renderer
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
}</jsitem>
<jsitem location="inlinesnippet" name="createRelatedRecords" cachelocation="false">var params = arguments[0],
	$ = skuid.$,
	productModel = skuid.$M('Product2Data'),
    row = productModel.getFirstRow(),
    productId = productModel.getFieldValue(row, 'Id');
    pricebookString = productModel.getFieldValue(row, 'UiOnlyMultiselect');
    arrayJunctionObject = pricebookString.split(';'),
    junctionObject = skuid.$M('Pricebook_Entries');


$.each(arrayJunctionObject, function(i, row){
    junctionObject.createRow({
        additionalConditions: [
            { field: 'Product2Id', value: productId},
            { field: 'Pricebook2Id', value: row},
        ], doAppend: true
    });i;
});</jsitem>
</javascript>
   </resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.