How to query approval status from multi row variable set

vahini
Giga Guru

Hello all, 

Please read my requirement below and advise on how to get it done.

Thanks In advance for reading my post till the end, appreciate your time.

 

I created a list collector referenced to u_cmdb_ci_ad_group table and a multi row variable set (active_directory_record_list)  which is hidden on form and visible only on RITM after submission.

 

List collector

 

 

Multi row variable set looks like below 

 

 

 

if any of AD Group has no secondary approver then it's automatically marked as Approved by some script ,and if there is a secondary approver then it's sent for approval to that person and that person might approve or reject.

 

once approval is done, in the next step i am sending a payload to OIM tool and in it sending approved groups.

 

currently i am sending all approved groups in payload , but customer wants to see only approved AD groups and not rejected one.

 

querying selected AD groups against cmdb_ci_ad_group table and finding display values.

vahini_3-1737470859638.png

 

adding all those groups in the payload.

vahini_4-1737470897413.png

 

in below screen shot highlighted group was rejected as shown in RITM (2nd screen shot above ), this should not go in the payload.

vahini_5-1737471114911.png

 

Please advise on how to get only approved groups and send it in payload. 

 

Thank you so much for your time.

 

 

1 ACCEPTED SOLUTION

Hi Ankur, 

 

I used the code you posted and modified it to below code, but it's throwing one error, not sure whats wrong in code, all variables are correct names.

 

var parseData = JSON.parse(fd_data._1__get_catalog_variables.active_directory_record_list.toString());
var approvedGroup = [];
for(var i=0;i<parseData.length;i++){
// use correct variable name and value to compare
if(parseData.approval_status.toString() == 'approved')
{
approvedGroup.push(parseData.u_select_group.toString()); // use correct group name variable within MRVS
}
}
return approvedGroup.toString();

 

vahini_0-1737483988457.png

 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@vahini 

you can get the complete MRVS JSON, iterate and then check the status is approved then only push that value in array

what is the script include and the function?

something like this

var parsedData = JSON.parse(fd_data._1__get_catalog_variables.active_directory_record_list.toString());
var approvedGroup = [];
for(var i=0;i<parsedData.length;i++){
// use correct variable name and value to compare
if(parsedData.approval_status.toString() == 'Approved')
approvedGroup.push(parsedData.group_name.toString()); // use correct group name variable within MRVS
}
return approvedGroup.toString();

AnkurBawiskar_0-1737471868679.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, 

 

I used the code you posted and modified it to below code, but it's throwing one error, not sure whats wrong in code, all variables are correct names.

 

var parseData = JSON.parse(fd_data._1__get_catalog_variables.active_directory_record_list.toString());
var approvedGroup = [];
for(var i=0;i<parseData.length;i++){
// use correct variable name and value to compare
if(parseData.approval_status.toString() == 'approved')
{
approvedGroup.push(parseData.u_select_group.toString()); // use correct group name variable within MRVS
}
}
return approvedGroup.toString();

 

vahini_0-1737483988457.png

 

@vahini 

did you publish the flow because now in your script there is no script include code but the logs say error in script include

Script looks fine to me

Are you using the correct variable names and value to compare?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Below script worked for me

 

var approvedADGgroups = [];

var mrvsAapproval = JSON.parse(fd_data.trigger.request_item.variables.active_directory_record_list.toString());
for (var i = 0; i < mrvsAapproval.length; i++) {
    if (mrvsAapproval[i].approval_status == 'approved') {
        approvedADGgroups.push(mrvsAapproval[i].u_select_group)
    }
}

var t = 'u_cmdb_ci_ad_group';
var l = approvedADGgroups;
var dv = new getLCDisplayValues().getValues(t, l);
return dv.trim();