Adopt Rows into Model for 2 different objects?

Is it possible to use the Adopt rows into Model action type in one object and create rows in a different object? (Just to clarify, I’m talking about 2 different salesforce objects, not models)

I would like to allow the user to select multiple rows of one object and have it create rows in a different table for a different object. The objects are similar but not the same. I feel like this is not possible because I don’t see how it would know which fields to pass where, but thought I’d put it out there.

Thanks.

Chelsea,

The “Adopt Rows” action is intended to move rows of the same type of object between different Models on the same object.

The “Create new row(s)” Action, however, should be able to do what you’re after – if you select one or more rows in one Model, and then add a Mass Action with a single “Create new rows” Action, with the “Model to create new rows in” property set to a _different_ Model, you will be creating one row in the other Model for each row in the source Model. Then you will need to click “Add Default Value” to your Create new row action to add a default value for field you want to “map” from the source row to the new row in the target Model.

For example, I’m attaching the XML for an Opportunity detail page where you can click an “Add Line Items” Global Action on the “Products” tab which lets you pick Products from the PricebookEntry object in Salesforce, and then creates new OpportunityLineItem records in a related Model via a “Create new row” action with a few Default Values that map fields from the source PricebookEntry into each new OpportunityLineItem record:

Here is the link to this sample page’s XML.

Is there any way to do this programatically? In other words – Let’s say I want to create new rows in a different object (or UI) destination model for all rows in a source (object/aggregate) model but have that be done as part of a process that is doing several other things as well. Is this possible? (loop over all rows in source model and create rows in destination model?)

I’ve figured out how to iterate over all rows in a source model and add them to a destination model via javascript snippet. This allows you to adopt rows of one object type into a model of another object type, or even create rows based on conditions. This is also a good template for iterating over models and performing actions in general.

Code below (still not sure the best way to paste code here):

var params = arguments[0],

$ = skuid.$;


//Source Model containing rows we’ll iterate over

var sourceModel = skuid.model.getModel(‘SourceModelName’);

//Destination Model to create new rows in

var destModel = skuid.model.getModel(‘DestModelName’);

//If we have a parent model containing our parent object that we’ll get the ID from to associate our newly created rows with (eg. Parent: Invoice, Child: Invoice Line Items with lookup relationship to parent)

var parentModel = skuid.model.getModel(‘ParentModelName’);

var parentRow = parentModel.getFirstRow();

var parentId = parentModel.getFieldValue(parentRow,‘Id’);


//Remove all rows from destModel so we start fresh

destModel.abandonAllRows();

//Iterate over our source model, creating new rows in our destination model and updating those rows with whatever values from our source model that we are looking to move over to the destination model (also a reference to our parent model if we’re using a parent model)

$.each(sourceModel.data,function(i,row){

    var cRow = destModel.createRow({doAppend: true});

    destModel.updateRow(cRow,{

       DestField1__c: sourceModel.getFieldValue(row,‘FieldName’,true),

       ParentIdField__c: parentId

   });

});