create formula for the value of a new row item

  • 1
  • Question
  • Updated 2 months ago
  • Answered
I am creating a new row item from the products table,   What I want to do is make a calculation that hits two models and then does math to get a new value that I can then pass to as a variable when creating a new row. 

i.e. I want to take get the result of ( products.BasePrice * Oppurtunity.CommissionRate ) 

and take that result and put it into the value of a table action propery

My guess is that I have to write some formula in the value for the table action property 

I looked around and thought that VALUE({{BasePrice}})+VALUE({{Oppurtunity.CommissionRate}}) might work but it comes out as text.   

Any ideas? 
Photo of Ambrose alward

Ambrose alward

  • 70 Points

Posted 3 months ago

  • 1
Photo of Gregg Baxter

Gregg Baxter, Official Rep

  • 3,080 Points 3k badge 2x thumb
Hi Ambrose.

You can create a Ui Only Field on your resulting Model and set the display type to 'Formula' and Formula Return Type to number and your formula could look something like this: ({{$Model.NumbersModel.data.0.BasePrice}} * {{$Model.NumbersModel.data.0.CommissionRate}}) / 100 – the formula addresses the model with the data you want to calculate and the inserts the value into the UI only field which you could use to update and store on the desired field.  Here is the XML.  I am using Ui only models here.  Just create a new page and choose 'Paste XML from a prebuilt page' and copy and paste the XML in. 

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true">
<models>
<model id="NumbersModel" limit="20" query="true" createrowifnonefound="false" datasource="Ui-Only" processonclient="true">
<fields>
<field id="BasePrice" displaytype="DOUBLE" label="Base Price" ogdisplaytype="TEXT" precision="9" scale="2"/>
<field id="CommissionRate" displaytype="PERCENT" label="Commission Reate" ogdisplaytype="TEXT" precision="2" scale="0"/>
</fields>
<conditions/>
<actions/>
</model>
<model id="CalcModel" limit="20" query="true" createrowifnonefound="false" datasource="Ui-Only" processonclient="true">
<fields>
<field id="NewValue" displaytype="FORMULA" label="New Value" ogdisplaytype="TEXT" readonly="true" returntype="DOUBLE" precision="9" scale="2">
<formula>({{$Model.NumbersModel.data.0.BasePrice}} * {{$Model.NumbersModel.data.0.CommissionRate}}) / 100</formula>
</field>
</fields>
<conditions/>
<actions/>
</model>
</models>
<components>
<skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="client" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="true" model="NumbersModel" buttonposition="" mode="read" allowcolumnreordering="true" responsive="true" uniqueid="sk-2Umq-605">
<fields>
<field id="BasePrice" uniqueid="fi-2Umq-606"/>
<field id="CommissionRate" uniqueid="fi-2Umq-607"/>
</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>
<skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="client" searchbox="true" showexportbuttons="false" hideheader="false" hidefooter="false" pagesize="10" alwaysresetpagination="false" createrecords="true" model="CalcModel" buttonposition="" mode="read" allowcolumnreordering="true" responsive="true" uniqueid="sk-2Unl-1141">
<fields>
<field id="NewValue" uniqueid="fi-2Unl-1142"/>
</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/>
<javascript/>
<css/>
<actionsequences uniqueid="sk-2UmQ-388">
<actionsequence id="77d957b5-ac70-4a1a-bc67-bace27474e00" label="LoadData" type="event-triggered" event-scope="component" event-name="page.rendered" uniqueid="sk-2UnH-748">
<description/>
<actions>
<action type="createRow" model="NumbersModel" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
<defaults>
<default type="fieldvalue" field="BasePrice" enclosevalueinquotes="false" value="200"/>
<default type="fieldvalue" field="CommissionRate" enclosevalueinquotes="false" value="10"/>
</defaults>
</action>
<action type="save">
<models>
<model>NumbersModel</model>
</models>
</action>
</actions>
</actionsequence>
</actionsequences>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>