Hello -
When using the action framework to create a new row that specifies a default value on a reference field, the “reference” field counterpart contains a different value when the row added is the first row in the target model vs. any subsequent row.
Steps to Reproduce:
- Create a new Account View page (stock)
- Add Phone field to Account model
- Add Contact models - Do not specify any conditions
- Add AccountId, Account.Name, Account.Id, Account.Phone fields to contact model
- Add a contacts table including fields for Account.Name and Account.Phone
- Add a global action “Add New” that runs multiple actions. Add a create row action specifying a default for AccountId to {{$Model.Account.data.0.Id}}
- Identify an account that has a phone number field value but does not contain any contacts
- Preview the page using account from #7
- Click “Add new” - You will see both Account Name & Account Phone
- Click “Add new”
Actual Result
Account Phone is blank
Expected Result
Account Phone should have a value
Analysis
Skuid appears to be looping through Contact.data to find a row that contains an “Account” field and if it finds one, it uses the “Name” and applies only the “Name” to the “Account” on the contact. If it can’t find a row in Contacts with the same AccountId, it then looks through all models on the page for an “Account” model (using keyPrefix) and takes the “Account” field from there if it finds an account with the same Id. This results in a “full copy” of “__r” on the first record, but only the “Name” on subsequent records.
I can’t remember exactly, but I believe there was a thread a while back that indicated the “__r” would need to be established programmatically and that default values would only ever get “Name” when reference field is involved. Even if this is the case though, the behavior should be consistent on first row and subsequent rows otherwise UI rendering is different.
Ideally, the full “__r” can be retrieved from either another row in the Contacts model (instead of just the name) or from the keyPrefix lookup for the first one. This would avoid having to programmatically set the “__r” while also solving the problem of inconsistancy between first and subsequent records.
Sample XML
<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true" tabtooverride="Account"> <models>
<model id="Account" limit="1" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
<field id="Id"/>
<field id="Phone"/>
<field id="Type"/>
<field id="Description"/>
</fields>
<conditions>
<condition type="param" enclosevalueinquotes="true" operator="=" field="Id" value="id"/>
</conditions>
<actions/>
</model>
<model id="ContactWithCondition" limit="1" query="false" createrowifnonefound="false" sobject="Contact" doclone="" type="">
<fields>
<field id="Account.Name"/>
<field id="Account.Id"/>
<field id="Account.Phone"/>
</fields>
<conditions>
<condition type="modelmerge" value="" field="AccountId" operator="=" model="Account" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
</conditions>
<actions/>
</model>
<model id="ContactWithDefault" limit="1" query="false" createrowifnonefound="false" sobject="Contact" doclone="" type="">
<fields>
<field id="AccountId"/>
<field id="Account.Name"/>
<field id="Account.Id"/>
<field id="Account.Phone"/>
<field id="Name"/>
<field id="FirstName"/>
</fields>
<conditions/>
<actions/>
</model>
</models>
<components>
<pagetitle model="Account">
<maintitle>
<template>{{Name}}</template>
</maintitle>
<subtitle>
<template>{{Model.label}}</template>
</subtitle>
<actions/>
</pagetitle>
<skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="false" model="ContactWithDefault" buttonposition="" mode="edit">
<fields>
<field id="FirstName" valuehalign="" type=""/>
<field id="Account.Name" valuehalign="" type=""/>
<field id="Account.Phone" valuehalign="" type=""/>
</fields>
<rowactions/>
<massactions usefirstitemasdefault="true"/>
<views>
<view type="standard"/>
</views>
<actions defaultlabel="Global Actions" defaulticon="sk-icon-magic" usefirstitemasdefault="true">
<action type="multi" label="Add New" icon="sk-icon-magic">
<actions>
<action type="createRow" model="ContactWithDefault" appendorprepend="prepend" defaultmodefornewitems="edit">
<defaults>
<default type="fieldvalue" value="{{$Model.Account.data.0.Id}}" field="AccountId" enclosevalueinquotes="true"/>
</defaults>
</action>
</actions>
</action>
</actions>
</skootable>
</components>
<resources>
<labels/>
<css/>
<javascript/>
</resources>
</skuidpage>
Thanks!