I’m building a page and encountered some strangeness with Models, and have isolated the problem in a demo page. I’ll try and add the XML for this page into this post - if it doesn’t work, I’ll host elsewhere and link in the comments. It should work in any vanilla org with Accounts and Contacts.
There are two models - Account and Contacts. The idea is you can create an Account and Contacts for that account at the same time. As it’s a demo page, it’s a little weird, but essentially you enter an Account name at the top, then enter Contact email addresses in a table underneath. A button at the top Saves the Account first, then Contacts.
The Contacts model has a condition that sets the LastName field to the value from the Account Name - weird, but this is for demo purposes, so please bear with me
The idea here is that when saving the Contacts, the Account name should get pulled in and put into each Contact’s Last Name. This should be similar in principle to how I can link newly created Contacts to a newly created Account all in the same page, where the Contacts has a condition that sets AccountID to the ID field of the account. Skuid does the magic here.
But it doesn’t work like this for non-ID fields. In this case, the Last Name only gets set if the Account name is entered and a row is created in the model after this - and the value is only set on the new model, not any that existed before the Account Name was set (I’d be OK with this so long as on save, the value was copied, but that doesn’t seem to happen).
Similarly, if I create a new row in the Contacts model with the Javascript API, if Account Name is populated it ends up on the Contact record (I imagine that the + button in the table is calling createRow() in the background).
To demo this with the page, enter an Account name, enter an email address for the default row in the table, then click the + icon to add another row, put another email address in, and then click the button at the top. You should receive an error, but check the account that got created - the second contact was created with the last name set.
Am I wrong in my thinking of the way this should work? I have a workaround for now, but just curious! Here’s the code:
<skuidpage unsavedchangeswarning="yes" showsidebar="true" showheader="true"> <models> <model id="Account" limit="" query="false" createrowifnonefound="true" sobject="Account" doclone="" type=""> <fields> <field id="Name"/> </fields> <conditions/> <actions/> </model> <model id="Contacts" limit="" query="false" createrowifnonefound="true" doclone="" type="" sobject="Contact"> <fields> <field id="Email"/> <field id="LastName"/> </fields> <conditions> <condition type="modelmerge" value="" field="AccountId" operator="=" model="Account" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate"/> <condition type="modelmerge" value="" field="LastName" operator="=" model="Account" enclosevalueinquotes="true" mergefield="Name" novaluebehavior="deactivate"/> </conditions> <actions/> </model> </models> <components> <pagetitle model="Contacts"> <maintitle> <template>{{Name}}</template> </maintitle> <subtitle> <template>{{Model.label}}</template> </subtitle> <actions> <action type="multi" label="New Button"> <actions> <action type="save"> <models> <model>Account</model> <model>Contacts</model> </models> </action> </actions> </action> </actions> </pagetitle> <basicfieldeditor showheader="true" showsavecancel="false" model="Account" buttonposition="" mode="edit" layout=""> <columns> <column width="100%"> <sections> <section title="Section A"> <fields> <field id="Name" valuehalign="" type=""/> </fields> </section> </sections> </column> </columns> </basicfieldeditor> <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="false" showexportbuttons="false" pagesize="10" createrecords="true" model="Contacts" buttonposition="" mode="edit" emptysearchbehavior="query"> <fields> <field id="Email"/> </fields> <rowactions> <action type="edit"/> <action type="delete"/> </rowactions> <massactions usefirstitemasdefault="true"> <action type="massupdate"/> <action type="massdelete"/> </massactions> <views> <view type="standard"/> </views> <searchfields/> </skootable> </components> <resources> <labels/> <javascript/> <css/> </resources> </skuidpage>