- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2023 11:43 AM - edited 08-04-2023 10:55 AM
We have a rather complex form/workflow where based on the entries made into the Catalog Item, a work group has to go back and do a bunch of research, and determine all the different approvers who need to be involved in the process (could be 3, could be 60). So, after it goes through initial Manager Approval, a Task is created for the research team, where they populate a MRVS I created on the Form, that asks for Approver, Description, and a few other things. I then have a script that dynamically builds new Approvals, based on those entries (one for each row in the MRVS). All that works just fine without any issues.
Now here comes the tricky part. Once all the approvals are complete, I would like to run a script that will go back to the MRVS and update a field in there named "Status" with Approve or Rejected, indicating whether each Approval Record was approved or rejected. I have a script which loops through all the appropriate Approval records for the the a particular RITM, and then have it loop through the records in MRVS to look for a match. I am able to do all of that, I just cannot figure out how to update the existing MRVS records in my script, to set the Status field to the appropriate "Approved" or "Rejected" values.
Here is my code from my Run Script action:
//get sys_id of RITM
var ritmSysID = current.sys_id;
//initialize variables
var stVal = '';
var apAppCon = '';
var apOwner = '';
var apValue = '';
var apDesc = '';
var apState = '';
//query approval table
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval',ritmSysID);
gr.addQuery('u_approval_type','STARTSWITH','Entitlement Owner Approval');
gr.query();
while(gr.next()){
//get variables from approval record
stVal = gr.u_stored_values;
var apArr = stVal.split('~');
apOwner = apArr[0];
apAppCon = apArr[1];
apValue = apArr[2];
apDesc = apArr[3];
apState = gr.state;
//loop through all records in MRVS and find correct one
//get the MRVS
var mrvs = JSON.parse(current.variables.entitlement_owner_approvals);
//loop through all rows of MRVS
for (var i = 0; i < mrvs.length; i++) {
//check to see if all fields match
if((mrvs[i].owner==apOwner) && (mrvs[i].application_connector==apAppCon) && (mrvs[i].value==apValue) && (mrvs[i].description==apDesc)){
//update the status field
gs.log('MATCH: ' + apState,'JOE9');
mrvs[i].status = apState;
mrvs[i].update();
}
}
}
//update current record (***tried with and without this and it made no difference)
current.update();
I don't think it like the last line of code.
Does anyone know how I can update these existing MRVS records in my code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 10:57 AM
Here's a workflow script I use to update MRVS variables, adapted for your script:
var mrvs = current.variables.entitlement_owner_approvals;
var rowCount = mrvs.getRowCount();
//loop through all rows of MRVS
for (var i=0; i<rowCount; i++) {
var row = mrvs.getRow(i);
//check to see if all fields match
if (row.owner == apOwner && row.application_connector == apAppCon && row.value == apValue && row.description == apDesc) {
//update the status field
gs.log('MATCH: ' + apState,'JOE9');
row.status = apState.toString();
}
}
With this method you don't need an update() function on the MRVS or current/RITM record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 11:42 AM
I see that each row of the MRVS is stored in a table called "Multi Row Question Answer" (sc_multi_row_question_answer). So I think that if I could just find some way to get to the correct record in the table from my script, I could do a Glide Record query on that table, and update the record. Just cannot figure out how to get there,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 10:57 AM
Here's a workflow script I use to update MRVS variables, adapted for your script:
var mrvs = current.variables.entitlement_owner_approvals;
var rowCount = mrvs.getRowCount();
//loop through all rows of MRVS
for (var i=0; i<rowCount; i++) {
var row = mrvs.getRow(i);
//check to see if all fields match
if (row.owner == apOwner && row.application_connector == apAppCon && row.value == apValue && row.description == apDesc) {
//update the status field
gs.log('MATCH: ' + apState,'JOE9');
row.status = apState.toString();
}
}
With this method you don't need an update() function on the MRVS or current/RITM record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 07:25 AM
YES!!! That works!
Thank you so much!!! This has been vexing me for days!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 10:42 AM
You are welcome!