Adding rows in one object based on another

I have a custom “Account Rep” object that is a child of the “Account” object.  When an opportunity is entered under this account, I am trying (unsuccessfully) to iterate over the rows in the “Account Rep” object to add these reps to another custom object (commissions) that is a child of the opportunity object.

I tried to steal code from the “mass create records” example and my modifications are still lacking.  Specifically, I am having issues copying the owner id from one model to the other and I don’t know how to iterate through the rows.

My first model is called “Reps” and I want to copy the following fields:


To the model called “Commissions”.  Let’s just say the field names are the same.

This post may help. Not sure as I haven’t reviewed how it works.

The “mass create records” example has been the source of everything I’ve been able to do that looks like that.  You should be able to iterate over all records and send the owner ID and the relevant Rate values into the commission records. 

Another place this is done is in our opportunity detail page that is in our samples.   Download it here.   Just be ware that there is a static resource you need to add to your org for some of the capabilities to work correctly.    Once you ahve that built,  look at the Products tab and select the mass action “Generate Assets”

You should be able to make this work…  

No matter what I do, the only field that I can’t get to copy is my owner id.

Here’s my code:

var params = arguments[0];var $ = skuid.$;
// Get references to our two Models
var models =;
var reps = models.Reps;
var commissions = models.Commissions;

// Copy details from Reps to Commissions

var HTRate = reps.getFieldValue(row,‘Hang_Ten_Rate__c’);
var COOLARate = reps.getFieldValue(row,‘COOLA_Rate__c’);
var TBRate = reps.getFieldValue(row,‘Tommy_Bahama_Rate__c’);
var theOwner = reps.getFieldValue(row,‘OwnerId’);
var newrow = commissions.createRow({
        additionalConditions: [
            { field: ‘Hang_Ten_Rate__c’, value: HTRate, operator: ‘=’},
            { field: ‘COOLA_Rate__c’, value: COOLARate, operator: ‘=’},
            { field: ‘Tommy_Bahama_Rate__c’, value: TBRate, operator: ‘=’},
           { field: ‘OwnerId’, value: theowner, operator: ‘=’},

I fixed the spelling of “value:theowner” to “value:theOwner” and it still doesn’t work.

You have to add a “nameFieldValue” parameter with the owner name. So basically you would add a variable for the name in the loop:

var ownerName = reps.getFieldValue(row,'Owner.Name');

and then change the last line to this:

{ field: 'OwnerId', value: theowner, operator: '=', nameFieldValue: ownerName}

Thank you so much for this Moshe!!!

It worked perfectly!!!

Glad you were able to get this working…