Skip to main content

I have an object (table) that I want to populate with a set of template rows that will be stored in another object (table).

The skuid Action framework includes Adopt Rows Into Model, but I don’t find any documentation for it. The adoptRow() javascript function may provide background, but its definition refers to external data. It also talks about matching on Id’s.

Let me sketch this out a bit:

TARGET OBJECT


RecId Name Level Group Factor Data6 Data7 ...<br>----- ---- ----- ----- ------ ----- ----- ...


SOURCE OBJECT


RecId Name Level Group Factor Condition1 Condition2<br>ab001 1234 &nbsp;1 &nbsp; &nbsp; A &nbsp; &nbsp;Red &nbsp; &nbsp;Thursday &nbsp; Dent<br>ab002 1235 &nbsp;1 &nbsp; &nbsp; A &nbsp; &nbsp;Blue &nbsp; Thursday &nbsp; Dent<br>ab003 1236 2 &nbsp; &nbsp; A &nbsp; &nbsp;Yellow Thursday &nbsp; Dent<br>ab004 1237 1 &nbsp; &nbsp; A &nbsp; &nbsp;Red &nbsp; &nbsp;Monday &nbsp; &nbsp; Dent<br>ab005 1238 2 &nbsp; &nbsp; B &nbsp; &nbsp;White &nbsp;Monday &nbsp; &nbsp; Dent<br>ab006 1239 &nbsp;1 &nbsp; &nbsp; A &nbsp; &nbsp;Blue &nbsp; Monday &nbsp; &nbsp; Prefect<br>ab007 1240 &nbsp;2 &nbsp; &nbsp; B &nbsp; &nbsp;Green &nbsp;Thursday &nbsp; Prefect


I would have a model based on the Source object, with conditions for selecting by day and by person. I will query the model. If the condition values are  Monday and Dent, the model will contain 2 rows: Level 1, Group A, Factor Red; and Level 2, Group B, Factor White.

I want to copy these 2 rows into my Target model, as…


RecId Name Level Group Factor Data6 Data7 ...<br>ar01a 2468 1 &nbsp; &nbsp; A &nbsp; &nbsp; Red &nbsp; &nbsp;-----&nbsp;-----&nbsp;...<br>ar01b 2469 2 &nbsp; &nbsp; B &nbsp; &nbsp; White &nbsp;----- ----- ...

Will this work?

A few questions.

  1. Do the Source and Target objects have the same fields?

  2. When do you want to adopt the rows into the Target Object/Model?

  3. Don’t understand the need for two models. Can you provide the use case for this?


Use Case: Create an evaluation matrix from a template.
There will be a separate matrix for each client.
Based on criteria in the Client object, one of several templates will be used to initialize the matrix.

Re. 1
The source object contains multiple templates.
Each template consists of multiple records.
Certain fields in the source (template) object identify the template criteria and match the criteria fields in the Client object.
Other fields in the source/template match the fields in the Evaluation (target) object.
There are also some fields in the source object that are used for template maintenance. These are not used for selection criteria or copied to the target. (These also include the standard fields like createddate, name, id, etc.)

Re. 2
The page will have a Page Title component with a button for “Create Matrix”. It is rendered if the Evaluation (target) model has no data rows. (The Evaluation model includes a condition for a single Client Id.)
The Create Matrix button actions will:

  • Activate and set condition on the Template model

  • Query the template model

  • Copy the rows from the Template model into the Evaluation model

The action framework would allow creation of new rows in the Evaluation model and set default values according to a template, but then the template definition is embedded in the skuid actions. Changing a template rows and values would require changing the page. Pulling the rows in from a separate object allows the templates to be maintained independent of their use.


Ok. You should be able to adopt the rows into the target so long as you have fields with the same name in the target. Worst case is you have to create UI only fields with the same metadata settings in order for the rows/fields from the Source Target to display properly. Should be no problem.

How do you intend to adopt the rows? Once the Source table is queried, you can use a Row, Mass or Global Action w/ Action Framework to do this.


Adopt Rows works nicely - to a point. It apparently copies those fields with matching names (and meta-data?) from the source model to the target model. However, this also includes the standard Id field. Since the source and target models are different objects, the a2xr… Id’s from the source generate an “Invalid Id for Evaluation__c” error. The Evaluation Id is a2kr…

Apparently the Adopt Rows action expects the source and target models to use the same sObject. And, the target model will be using the SAME ROWS from that object.

Apparently, I will need to use javascript to copy from a template object to a target.



Hmmm … what is this a2xr and s2kr you speak of?


Is Evaluation__c the target object?


Anyway. The Adopt Rows action should work fine. Just created a test page.


<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" showheader="true"> <models> <model id="Tasks" limit="20" query="true" createrowifnonefound="false" adapter="salesforce" type="" sobject="Task"> <fields> <field id="WhatId"/> <field id="What.Name"/> <field id="WhoId"/> <field id="Who.Name"/> <field id="Subject"/> </fields> <conditions/> <actions/> </model> <model id="Events" limit="20" query="true" createrowifnonefound="false" adapter="salesforce" type="" sobject="Event"> <fields> <field id="WhatId"/> <field id="What.Name"/> <field id="WhoId"/> <field id="Who.Name"/> <field id="Subject"/> </fields> <conditions/> <actions/> </model> </models> <components> <skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="all" createrecords="true" model="Events" buttonposition="" mode="read" uniqueid="sk-34oo1t-138"> <fields> <field id="Subject"/> <field id="WhoId"/> <field id="WhatId"/> </fields> <rowactions> <action type="edit"/> <action type="delete"/> </rowactions> <massactions usefirstitemasdefault="true"> <action type="massupdate"/> <action type="massdelete"/> </massactions> <views> <view type="standard"/> </views> <actions defaultlabel="Global Actions" defaulticon="sk-icon-magic" usefirstitemasdefault="true"> <action type="multi" label="Adopt Tasks" icon="sk-icon-magic"> <actions> <action type="adoptRows" sourcemodel="Tasks" targetmodel="Events"/> </actions> </action> </actions> </skootable> </components> <resources> <labels/> <javascript/> <css/> </resources> <styles> <styleitem type="background" bgtype="none"/> </styles> </skuidpage>


Was there an answer to this question? I am looking to do something similar, and I am having trouble finding the solution. Thanks.


Sean -

I had enough of the javascript built that I went ahead with that method in the interest of time. I have not been back (yet) to load and evaluate Pat’s test page. You might try that if you have the time, and I could also share my javascript. I do wish there was documentation of the Adopt Rows action.

- Mike


Thanks for the reply Mike. If you don’t mid sharing the javascript, that would be awesome.

I tried Pat’s skuid page, but I was not able see how the adopt rows functionality would be pulling from a template table.


I hope this helps! The following is an Inline Snippet. It is called from a button action on a Page Title component.

// Get the Template and new Matrix models.
var template = skuid.model.getModel(‘CasePlanTemplateRows’);
var matrix   = skuid.model.getModel(‘CasePlanLevelFactors’);

// Walk the array of Template rows
var templateRows = template.getRows();
for ( i=0; i < templateRows.length; i++)
{
    // Get the template values from each row, one row at a time
    var templateRow = templateRows i];
    var templateSequence = template.getFieldValue( templateRow, ‘Row_Sequence__c’);
    var templateGroup    = template.getFieldValue( templateRow, ‘Factor_Group__c’);
    var templateFactor1  = template.getFieldValue( templateRow, ‘Level_1_Factor__c’);

    // Create a new matrix row; copy the template-row values into it
    var matrixRow = matrix.createRow( {doAppend:true} );
    matrix.updateRow( matrixRow, {
        Row_Sequence__c:   templateSequence,
        Factor_Group__c:   templateGroup,
        Level_1_Factor__c: templateFactor1
    })
}


Reply