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 = arguments[0],
$ = 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([OpptyModel],{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[j]);
}
}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