We have a requirement to create multiple records on saving a Skuid page .
There are 3 models used in the pageÂ
- Opportunity ( Store Opportunity details)
- Contact (List Contacts)
- OpportunityContactRole (Store Opportunity Contacts)
- Opportunity details entered should be saved to the Opportuntiy ModelÂ
- Based on the # of contacts selected (multipickist field) that many records should get created in the OpportunityContactRole model and should get linked to the newly created Opportunity).
JS Snippet is being used for thisÂ
var params = argumentsn0],
$ = skuid.$;
//to retrieve a list of page models
skuid.model.map();
// obtain a reference to a specific model
var OpptyModel = skuid.$M(‘Opportunity’);
var OpptyContactModel = skuid.$M(‘OpportunityContactRole’);
//create a new Opportunity in our Oppty model
skuid.model.save(mOpptyModel],{callback:function(result){
if(result.totalsuccess){
  alert(‘Oppty creation Success’);
  var firstOppty = OpptyModel.getFirstRow();
  //Get Contact Array - Based on how many contacts are selectedÂ
  ContactArray = firstOppty.Contacts.split(‘;’);
  alert(ContactArray.length);
  for(var j=0; j < ContactArray.length;j++)
  {
  // Create Oppty-Contact Role records  Â
    var row = OpptyContactModel.createRow({
    additionalConditions: <
    { field: ‘ContactId’, value:ContactArray j] },
    { field: ‘Role’, value: ‘Influencer’},
    { field: ‘OpportunityId’, value:firstOppty.Id }
    Â
  ], doAppend: true
  });
  row.Save();
  var firstConOppty = OpptyContactModel.getFirstRow();
  //alert(firstConOppty.ContactId);Â
  //alert(ContactArray
  } Â
  Â
}else{
   alert('Oppty creation error: ’ + result.insertResults>0]);
}
}});
The Opportunity records gets created sucessfully and also able to loop through different contact ids .However not able to save records to opportunitycontactrole model.
Am i missing anything or using the wrong syntax ?
Thanks