Hey Matt -
If I’m understanding what you’re after correctly - copying a row from one model to another but ensuring certain values aren’t copied over - then you might want to consider a different approach.
In short, the current approach you are taking relies on conditions to set the default values, however some of the fields that you are passing in are “__r” fields, etc. and those can’t have conditions. It’s possible that the javascript error you are encountering is the result of one of these fields.
Unfortunately, there isn’t an API to “copyRow” currently but the approach I would suggest is something along the lines of the following. Note that this is the “brute” force method and just copies every value (expect for those that you know you don’t want to copy). To really do this correctly, you should walk the target model and look in the source model for a field that matches by name and then grab that value. This ensures that you don’t put a field in to the target model row that exists in the source model but not the target. You can create a generic “copyRow” function that accepts a source model, source row, target model and target row and performs the copy.
That said, assuming that you know for certain that your source and target models are 100% the same, you could do this:
var $ = skuid.$ , sourceModel = skuid.$M('MergeCase')
, sourceRow = sourceModel.getFirstRow()
, targetModel = skuid.$M('PrimaryPatient'); // newRow is the row we're creating in the target model
// copiedRow is a copy of the row from the source model
var newRow = targetModel.createRow()
, copiedRow = $.extend({}, sourceRow);
// delete the fields in the copied row we don't want
delete copiedRow['Id'];
delete copiedRow['attributes'];
delete copiedRow['Patient__c'];
// update the newly created row in the target model with the values we "copied"
targetModel.updateRow(newRow, copiedRow);
Again, this assumes the models are identical. If they are not, I’d suggest writing the generic “copyRow” method.
Here is a sample page that performs a copy based on Account SObject:
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true" tabtooverride="Account"> <models>
<model id="AccountSource" limit="1" query="true" createrowifnonefound="false" sobject="Account" adapter="" type="">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
<field id="ParentId"/>
<field id="Parent.Name"/>
</fields>
<conditions>
<condition type="param" enclosevalueinquotes="true" operator="=" field="Id" value="id"/>
</conditions>
<actions/>
</model>
<model id="AccountTarget" limit="20" query="false" createrowifnonefound="false" adapter="" type="" sobject="Account" doclone="">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
<field id="ParentId"/>
<field id="Parent.Name"/>
</fields>
<conditions/>
<actions/>
</model>
</models>
<components>
<pagetitle model="AccountSource" uniqueid="sk-3pE7jy-67">
<maintitle>
<template>{{Name}}</template>
</maintitle>
<subtitle>
<template>{{Model.label}}</template>
</subtitle>
<actions>
<action type="multi" label="Copy Row To Target">
<actions>
<action type="custom" snippet="copyRowToTarget"/>
</actions>
</action>
</actions>
</pagetitle>
<basicfieldeditor showsavecancel="false" showheader="true" model="AccountSource" mode="read" uniqueid="sk-3pE7jy-68" buttonposition="">
<columns>
<column width="50%">
<sections>
<section title="Basics" collapsible="no">
<fields>
<field id="Name"/>
<field id="ParentId"/>
</fields>
</section>
</sections>
</column>
<column width="50%">
<sections>
<section title="System Info">
<fields>
<field id="CreatedDate"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
<basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="AccountTarget" buttonposition="" uniqueid="sk-3pFktd-322" mode="read">
<columns>
<column width="50%">
<sections>
<section title="Section A" collapsible="no">
<fields>
<field id="Name"/>
<field id="ParentId" valuehalign="" type=""/>
</fields>
</section>
</sections>
</column>
<column width="50%">
<sections>
<section title="Section B" collapsible="no">
<fields>
<field id="CreatedDate"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
</components>
<resources>
<labels/>
<css/>
<javascript>
<jsitem location="inlinesnippet" name="copyRowToTarget" cachelocation="false">var $ = skuid.$,
sourceModel = skuid.$M('AccountSource'),
sourceRow = sourceModel.getFirstRow(),
targetModel = skuid.$M('AccountTarget');
// newRow is the row we're creating in the target model
// copiedRow is a copy of the row from the source model
var newRow = targetModel.createRow()
, copiedRow = $.extend({}, sourceRow);
// delete the fields in the copied row we don't want
delete copiedRow['Id'];
delete copiedRow['attributes'];
delete copiedRow['ParentId'];
// update the newly created row in the target model with the values we "copied"
targetModel.updateRow(newRow, copiedRow);
</jsitem>
</javascript>
</resources>
<styles>
<styleitem type="background" bgtype="none"/>
</styles>
</skuidpage>