Adding rows in one object based on another

bimbycbimbyc Member
edited June 25 in Questions
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:

Owner
Rate1__c
Rate2__c
Rate3__c

To the model called "Commissions".  Let's just say the field names are the same.

Comments

  • Rob HatchRob Hatch Skuad, Sonar ✭✭
    edited September 2016
    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...  




  • bimbycbimbyc Member
    edited November 2014
    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 = skuid.model.map();
    var reps = models.Reps;
    var commissions = models.Commissions;

    // Copy details from Reps to Commissions
    $.each(reps.data,function(i,row){



    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: '='},
            ]
        });
    })
  • bimbycbimbyc Member
    edited November 2014
    I fixed the spelling of "value:theowner" to "value:theOwner" and it still doesn't work.
  • Moshe KarmelMoshe Karmel Member
    edited September 2016
    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}
  • bimbycbimbyc Member
    edited November 2014
    Thank you so much for this Moshe!!!!!!!!!

    It worked perfectly!!!!!!
  • Rob HatchRob Hatch Skuad, Sonar ✭✭
    edited September 2016
    Glad you were able to get this working.. 
Sign In or Register to comment.