- 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-25-2024 10:33 PM
Hi Brad,
with that row loop in the mrvs,
can the .actions field in the row be accessed in workflow,
I'm manipulating this field in the Catalog UI Policy but unable to read it in the workflow script,
am i missing something ?
/// a cut from your reply
var mrvs = current.variables.entitlement_owner_approvals;
var rowCount = mrvs.getRowCount();
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();
/////// Need the value where previously stored some unique sysid +someid from Catalog GUI Policy on change
var actionsValue = row.actions ///<— not returning value in WF but working in Catalog UI policy
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 03:49 AM
The JSON value of the entire MRVS stored in the database does not contain actions, only the name/value of each MRVS variable, so this isn't available when you retrieve the MRVS in a server script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 04:25 AM
Got it thanks.
Thats the big difference in Catalog Client script and Workflow(Server script) on MRVS is the .actions
here is my code in Catalog client script which actions is available, but not in workflow 😞 …, been using .actions column because it is hidden on screen, which is highly required to make it invisible to requestor…
any help in using any column in MRVS that is not visible but available in WF ?
any thought will be appreciated if there is.