Set value for field from another model when adding a row

  • 1
  • Question
  • Updated 8 months ago
  • In Progress
So I am trying to set the value of a new row field via the save button.   The value should be the Sales_Rep__r.Id from the object Opp,   Saved to 
Sales_Rep_1__c on the OppItem object.   

From the documentation I though I just needed to call the value via {{$Model.Opp.data.0.Sales_rep_r.Id}} or Opp.Sales_rep_r.Id  But when ever I try like below, nothing is passed to the new field.   

Any ideas?



<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="Opp" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Opportunity">
            <fields>
                <field id="Sales_Rep__c"/>
                <field id="Sales_Rep__r.Name"/>
                <field id="Sales_Rep__r.Id"/>
            </fields>
            <conditions>
                <condition type="param" value="id" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="noquery"/>
            </conditions>
            <actions/>
        </model>
        <model id="OppItem" query="false" createrowifnonefound="false" datasource="salesforce" sobject="OpportunityLineItem">
            <fields>
                <field id="Sales_Rep_1__c"/>
                <field id="Sales_Rep_1__r.Name"/>
                <field id="Sales_Rep_1__r.Id"/>
                <field id="Product2Id"/>
                <field id="Product2.Name"/>
                <field id="OpportunityId"/>
                <field id="Opportunity.Name"/>
                <field id="Quantity"/>
                <field id="UnitPrice"/>
            </fields>
            <conditions>
                <condition type="param" value="id" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="noquery"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <buttonset model="Opp" uniqueid="sk-Lk3-464">
            <buttons>
                <button type="multi" label="save" uniqueid="sk-Lk3-469">
                    <actions>
                        <action type="createRow" model="OppItem" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                            <defaults>
                                <default type="fieldvalue" field="Sales_Rep_1__c" fieldtargetobjects="Sales_Rep__c" enclosevalueinquotes="true" value="{{$Model.Opp.data.0.Sales_rep_r.Id}}"/>
                                <default type="fieldvalue" field="OpportunityId" fieldtargetobjects="Opportunity" enclosevalueinquotes="true" value="{{$Model.Opp.data.0.Id}}"/>
                                <default type="fieldvalue" field="Quantity" fieldtargetobjects="OpportunityLineItem" enclosevalueinquotes="false" value="2"/>
                                <default type="fieldvalue" field="UnitPrice" fieldtargetobjects="OpportunityLineItem" enclosevalueinquotes="false" value="1"/>
                                <default type="fieldvalue" field="Product2Id" fieldtargetobjects="Product2" enclosevalueinquotes="true" value="01tf4000001AsVfAAK"/>
                            </defaults>
                        </action>
                        <action type="save">
                            <models>
                                <model>OppItem</model>
                            </models>
                        </action>
                        <action type="redirect" window="self" url="/{Id}"/>
                    </actions>
                </button>
            </buttons>
        </buttonset>
        <richtext multiple="false" uniqueid="sk-LlP-666" model="OppItem">
            <contents>&lt;p&gt;{{Sales_Rep__r.Id}} should&amp;nbsp; {{$Model.Opp.data.0.Sales_Rep_r.Id}}&lt;/p&gt;
</contents>
        </richtext>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
        <actionsequences uniqueid="sk-LjW-353"/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>

Photo of Ambrose Alward

Ambrose Alward

  • 390 Points 250 badge 2x thumb

Posted 8 months ago

  • 1
Photo of Mike Dwyer

Mike Dwyer, Champion

  • 4,686 Points 4k badge 2x thumb
It seems we have been unable to do this reliably also. The approach I've been shown is to set Conditions on the OppItem model, for Sales_Rep_1__c and for OpportunityId. Set the value as "Field from another model" and reference Opp. (You could also make those conditions filterable and use the "Activate & Set value of Model Condition" action if you needed to do so conditionally.)
Photo of Ambrose Alward

Ambrose Alward

  • 390 Points 250 badge 2x thumb
Hmmm Could you post an example,   I am trying that but not getting any results that way.
Photo of Mike Dwyer

Mike Dwyer, Champion

  • 4,686 Points 4k badge 2x thumb
Looking for an example, the first instance I checked actually uses the method you proposed here. I wondered if there were any difference, I looked at your page again and saw: {{$Model.Opp.data.0.Sales_rep_r.Id}}. But the field name is Sales_Rep__c. See if case isn't the case!