I have a snippet that iterates through rows in a model (RequestedMedRecs) and creates a task for each row that meets certain conditions. The snippet runs every time my model is saved. The task creation part of the snippet is working well.
After each task is created, I want to update the row (Request_Submitted__c = true) so that the row no longer meets the criteria for task creation. I think I need something along the lines of this, but can’t figure out where to put it within my snippet. The update on the row needs to happen after all the tasks have been created.
medRecModel.updateRow(row, {
‘Request_Submitted__c’ : ‘True’,
});
Here’s my full snippet:
var params = arguments[0],
$ = skuid.$;
var MedRecModel = skuid.model.getModel(‘RequestedMedRecs’);
var TaskModel = skuid.model.getModel(‘MedRecTasks’);
$.each(MedRecModel.getRows(),function(i,row){
if (row.Status__c == ‘Requested’ && row.Request_Submitted__c === false) {
var NewTask = TaskModel.createRow({
additionalConditions: [
{ field: ‘Status’, value: ‘Completed’ },
{ field: ‘Subject’, value: ‘Record Requested’},
{ field: ‘ActivityDate’, value: ‘TODAY’ },
{ field: ‘Date__c’, value: ‘NOW’ },
{ field: ‘Type’, value: ‘Call’ },
{ field: ‘Patient_Case_Id__c’, value: row.Case__c },
{ field: ‘WhatId’, value: row.Case__c },
{ field: ‘Description’, value: ‘Record Requested’},
]
});
}});
TaskModel.save();
Question
Snippet to create child records (Tasks) and update parent record

This topic has been closed for comments
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.