In developing a clone page, we are encountering a couple of issues, both of which are rather difficult to describe so instead I provide a sample page (using SkuidCRM) that replicates the issue. Please note that the design of this sample page doesn’t have any real world applicability, it’s main purpose is to replicate what we’re doing in our real page by applying the same concepts. The SkuidCRM example just gives me the ability to reduce surface area for the actual repro of the problems.
Steps to repro:
- Add page below to SkuidCRM org
- Using preview button on page (make sure to add clone=1 to URL manually) or setup skuid to use this page to clone an account
- Pick an account to clone - based on model conditions you must be the owner of the account for the account to display. This condition is required to demonstrate the issues below
Actual Result
- Owner ID field is empty
Expected Result
2) Owner ID field should contain name of logged in user
Note - If you remove the lookup filter on Owner ID field, then Owner ID will display the proper value. As mentioned above, this particular lookup filter makes no sense in the real world but it is consistent with the type of filter we need in our application.
Looking underneath the covers, here is what is going on:
- Because this is a “clone” page, each recordin each model is being cloned even though we really only want AccountData to be cloned
- Since the “Id” of UserData model is “clone_#”, the lookup condition fails
skuid.model.getModel(‘UserData’).getFirstRow().Id == 'clone_1" - Even if you change the model condition from using (UserData)(Id) to a hardcoded string value of the ID of the user (e.g. “00540000002LeH4AAK”), Owner ID on the page is still empty. You can see this in action on the 2nd sample page below (HardCoded Approach), just make sure to update the model condition value for OwnerId field to the ID of your user.
skuid.model.getModel(‘AccountData’).getFirstRow().OwnerId = “”
Questions:
- Is there a way to force Skuid to not “clone” a model even if the URL paramater contains “clone=1”? In short, if I could find a way to only clone specific models, I think this would work around the above.
- Short of #1, I tried some workarounds to replicate something similar to hardcoding a value. Basically, create a formula field that exposes the ID of a record in a location where skuid won’t change it due to cloning. Unfortunately, as described in #3 above, this approach won’t work because even though the UserData model Id field isn’t used, the lookup ID field in AccountData (OwnerID) is still blank - This seems very odd btw. I can explain why it’s blank in the first page below (because Id is getting a value of clone_#) but can’t quite explain why the 2nd page isn’t working as expected.
I have a more realistic repro available if you are interested. Thank you!!
Dynamic Approach
<skuidpage showsidebar="false" showheader="true" tabtooverride="Account"> <models>
<model id="UserData" limit="100" query="true" createrowifnonefound="false" sobject="User">
<fields>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions>
<condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
</conditions>
</model>
<model id="AccountData" limit="1" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
<field id="AccountNumber"/>
<field id="CreatedById"/>
<field id="CreatedBy.Name"/>
<field id="OwnerId"/>
<field id="Owner.Name"/>
<field id="ParentId"/>
<field id="Parent.Name"/>
<field id="Id"/>
</fields>
<conditions>
<condition type="param" operator="=" field="Id" value="Id" mergefield="Id" enclosevalueinquotes="true"/>
<condition type="modelmerge" value="" field="OwnerId" operator="=" model="UserData" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
</conditions>
</model>
<model id="OriginalAccount" limit="1" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Name"/>
</fields>
<conditions>
<condition type="param" value="id" field="Id" operator="=" enclosevalueinquotes="true"/>
</conditions>
</model>
</models>
<components>
<pagetitle model="OriginalAccount">
<maintitle>New {{Model.Label}}</maintitle>
<subtitle>(Cloned from {{{Name}}})</subtitle>
<actions>
<action type="savecancel" label="New Action" afterSave=" /{{Id}}" afterCancel="/{{$Param.id}}" window="self">
<models>
<model>AccountData</model>
<model>Contact</model>
<model>Opportunities</model>
<model>Cases</model>
</models>
</action>
</actions>
</pagetitle>
<basicfieldeditor showsavecancel="false" showheader="true" model="AccountData" mode="edit">
<columns>
<column width="100%">
<sections>
<section title="General Info">
<fields>
<field id="Name"/>
<field id="ParentId">
<label>Parent Account</label>
</field>
<field id="OwnerId">
<filters>
<filter type="dependent" operator="=" field="Id" value="" enclosevalueinquotes="true" depfield="OwnerId"/>
</filters>
</field>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
</components>
<resources>
<labels/>
<css/>
<javascript/>
</resources>
</skuidpage>
Hardcoded Approach
<skuidpage showsidebar="false" showheader="true" tabtooverride="Account"> <models>
<model id="UserData" limit="100" query="true" createrowifnonefound="false" sobject="User">
<fields>
<field id="Id"/>
<field id="Name"/>
</fields>
<conditions>
<condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
</conditions>
</model>
<model id="AccountData" limit="1" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
<field id="AccountNumber"/>
<field id="CreatedById"/>
<field id="CreatedBy.Name"/>
<field id="OwnerId"/>
<field id="Owner.Name"/>
<field id="ParentId"/>
<field id="Parent.Name"/>
<field id="Id"/>
</fields>
<conditions>
<condition type="param" operator="=" field="Id" value="Id" mergefield="Id" enclosevalueinquotes="true"/>
<condition type="fieldvalue" value="00540000002LeH4AAK" enclosevalueinquotes="true" field="OwnerId"/>
</conditions>
</model>
<model id="OriginalAccount" limit="1" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Name"/>
</fields>
<conditions>
<condition type="param" value="id" field="Id" operator="=" enclosevalueinquotes="true"/>
</conditions>
</model>
</models>
<components>
<pagetitle model="OriginalAccount">
<maintitle>New {{Model.Label}}</maintitle>
<subtitle>(Cloned from {{{Name}}})</subtitle>
<actions>
<action type="savecancel" label="New Action" afterSave=" /{{Id}}" afterCancel="/{{$Param.id}}" window="self">
<models>
<model>AccountData</model>
<model>Contact</model>
<model>Opportunities</model>
<model>Cases</model>
</models>
</action>
</actions>
</pagetitle>
<basicfieldeditor showsavecancel="false" showheader="true" model="AccountData" mode="edit">
<columns>
<column width="100%">
<sections>
<section title="General Info">
<fields>
<field id="Name"/>
<field id="ParentId">
<label>Parent Account</label>
</field>
<field id="OwnerId">
<filters>
<filter type="dependent" operator="=" field="Id" value="" depfield="OwnerId" mergefield="Id" novaluebehavior="deactivate" enclosevalueinquotes="true"/>
</filters>
</field>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
</components>
<resources>
<labels/>
<css/>
<javascript/>
</resources>
</skuidpage>