Snippet to create child records (Tasks) and update parent record
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();
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();
Tagged:
1
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
MedRecModel.updateRow(row, {
Request_Submitted__c : 'True',
});
with this:
MedRecModel.updateRow(row, {
Request_Submitted__c : true,
});
Except...
I am getting some weird, jumpy behavior in the UI...it almost seems like this action is running on "row in model updated", not on "row saved." (I'll add new records to my table and they'll save before I hit the save button.) This seems to be working better when I remove the snippet. I'm going to go through all of my model actions to see if I can find any other likely culprits, but if you have any thoughts or have seen this before...I'd be interested!
I'm not quite following you. Are you trying to create a child record for every record that meets particular conditions? Are you having trouble getting records to show in your table, or trouble selecting a subset of records from that table? (The conditions on my RequestedMedRecs model has nothing to do with whether or not child records exist.)
One thing to check - make sure that any fields that you use as conditions in your snippet are selected in your model!
I think what you will need to do is requery your Matters model whenever the Receipts model is saved. Your Matters model should have the condition "Matters where ID is in Matter__c field from the Receipts model". Make sure you use "is in" instead of "=". This should return rows in your Matters model, and then you can update rows in that model.