Iterate over data and change the value of a field until condition is not met anymore. - No more Code!

  • 1
  • Praise
  • Updated 4 years ago
I have discovered a new way using multiple actions to iterate over data and change the value of a field until a condition is not met anymore thus ending the batch process.

Requirement:  Update all stock quantity values from 0 to 1

One Model = StockDataModel

A) First set Model Actions:
2 Model Actions Settings for StockDataModel =

1st action = When Model Saved then run one action
Action = Query Model (Behavior = Standard, completely replace data)

2nd action = When Model re-queried then run 2 actions
Action = Update a field on row(s) field:Quantity value:1
Action = Save Model StockDataModel.

B) Create a Button (on Page Title) action type = multiple actions
1st action = Update a field on row(s) field:Quantity value:1
2nd action = Save Model StockDataMode
3rd action = Query Model (Behavior = Standard, completely replace data)

C) Set Model Condition:
field:Quantity is not = 1
condition set to = is always on

This way the update will be invoked when the user clicks on the button.
The multiple actions on the Model Actions kick in and begin to iterate over the data until the model condition is no longer met and there is no more data to display in the Model.

This can be used in many different ways including allowing the user to enter a value as to how many times this should happen, for example when creating x amount of Items, and filtering on the updated changing value of the user input (i.e. 10 = input value -1 for every update) when performing the updates to end the process.

Just loving Skuid Summer 14!!

 
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
er ... uh ... I kinda get it. Mostly don't though. Can you provide an example page and/or video?
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
For this basic example I have created a custom object called Item with fields:
1. Name (Primary)
2. Quantity (Number 10,0)

The Page button changes the value from 0 to 1 and invokes the batch update.

Here is the XML.

<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true" tabtooverride="Item__c">   <models>
      <model id="ItemsOne" limit="100" query="true" createrowifnonefound="false" sobject="Item__c">
         <fields>
            <field id="Name"/>
            <field id="CreatedDate"/>
            <field id="Quantity__c"/>
         </fields>
         <conditions>
            <condition type="fieldvalue" value="1" enclosevalueinquotes="false" field="Quantity__c" operator="!="/>
         </conditions>
         <actions>
            <action>
               <actions>
                  <action type="updateRow" fieldmodel="ItemsOne" field="Quantity__c" enclosevalueinquotes="false" value="1"/>
                  <action type="save">
                     <models>
                        <model>ItemsOne</model>
                     </models>
                  </action>
               </actions>
               <events>
                  <event>models.loaded</event>
               </events>
            </action>
            <action>
               <actions>
                  <action type="requeryModels" model="ItemsChangedToZero" behavior="standard">
                     <models>
                        <model>ItemsOne</model>
                        <model>NewItems</model>
                     </models>
                  </action>
               </actions>
               <events>
                  <event>models.saved</event>
               </events>
            </action>
         </actions>
      </model>
      <model id="NewItems" limit="100" query="true" createrowifnonefound="false" sobject="Item__c" doclone="" type="">
         <fields>
            <field id="Name"/>
            <field id="Quantity__c"/>
         </fields>
         <conditions/>
         <actions/>
      </model>
   </models>
   <components>
      <pagetitle model="NewItems">
         <maintitle>
            <template>{{Model.labelPlural}}</template>
         </maintitle>
         <subtitle>
            <template>Home</template>
         </subtitle>
         <actions>
            <action type="multi" label="Change Quantity to 1" window="self" icon="sk-icon-return">
               <actions>
                  <action type="updateRow" fieldmodel="ItemsOne" field="Quantity__c" enclosevalueinquotes="false" value="1"/>
                  <action type="save">
                     <models>
                        <model>ItemsOne</model>
                     </models>
                  </action>
                  <action type="requeryModels" model="NewItems" behavior="standard">
                     <models>
                        <model>ItemsOne</model>
                        <model>NewItems</model>
                     </models>
                  </action>
               </actions>
            </action>
         </actions>
      </pagetitle>
      <skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="NewItems" buttonposition="" mode="read">
         <fields>
            <field id="Name"/>
            <field id="Quantity__c"/>
         </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>
   <resources>
      <labels/>
      <css/>
      <javascript/>
   </resources>
</skuidpage>