approvals based on MRVS field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 12:42 AM
Hi,
I have a catalogue item where we have a MRVS, in that multiple rows can be added and based on the variable(from MRVS) we need to trigger approvals through workflow, can someone please help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 01:44 AM
Hi @Anubhav Srivas1
Creating an approval process based on Multi-Row Variable Set (MRVS) variables obtained from a Service Catalog item involves a bit more complexity. This scenario requires parsing the MRVS data for each row, checking the conditions based on your requirements, and then triggering the appropriate approvals. This guide will outline a method to achieve this in ServiceNow using Flow Designer.
### 1. Parse MRVS Data
When a Catalog Item with a Multi-Row Variable Set is submitted, the data from the MRVS is not directly available as separate fields but is captured in a serialised JSON format. To work with this data, you’ll first need to parse it.
### Create a Flow
Step 1: Navigate and Create a New Flow
- Log into ServiceNow.
- Navigate to Flow Designer.
- Choose to create a new Flow.
- Give the Flow an appropriate name, related to the catalog item process.
Step 2: Define the Trigger
- Set the trigger based on the submission of a Catalog Item request. This could be when a Requested Item (sc_req_item) is created or updated to a specific state.
- Select the Data Pill for the Catalog Item’s variables or the specific MRVS field if available to pass it to the flow actions.
Step 3: Add Action to Parse MRVS Data
- Add an Action block where you will parse the JSON data from the MRVS.
- If not directly supported, you may need to use a Script step here to achieve the parsing. Use a Script Action to extract the MRVS data into a usable format. You’ll often use the JSON.parse() functionality in a server-side JavaScript to iterate over each row of the MRVS.
Example Script Snippet to Parse MRVS:
var parsedData = [];
var mrvsData = ‘’; // Assume this is the JSON string from your MRVS variable
try {
mrvsData = JSON.parse(current.variables.multi_row_variable_set); // Replace ‘multi_row_variable_set’ with the actual MRVS variable name
mrvsData.forEach(function(row) {
parsedData.push({
‘variableName1’: row.variableName1, // Replace ‘variableName1’ with your actual variable name
‘variableName2’: row.variableName2, // Similarly, replace ‘variableName2’
// Add more variables as required
});
});
} catch(e) {
// Handle error
}
// Now parsedData contains an array of objects for each row
Step 4: Loop Over Each Row and Trigger Approvals
- After parsing the MRVS data, use a For Each loop action to iterate over each row.
- Inside the loop, based on the conditions you need (e.g., a specific variable value within a row), add the logic to create an Approval.
Step 5: Customize Approval Logic
- Use the Create Approval action within the loop for scenarios meeting your specific condition. Set the Approver dynamically based on data in the MRVS row or static rules as required.
### Testing and Activation
- Thoroughly test your flow in a sub-production instance before deploying it to production. Ensure your parsing logic correctly interprets the MRVS data, and the approvals trigger as expected.
- After successful testing, activate your Flow.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 02:38 AM
Hello Deepak,
can we do it through a workflow editor?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 02:54 AM
Hello @Anubhav Srivas1
yes, you will do it through workflow also but configuring workflows that involve triggering approvals based on multiple row variable set (MRVS) values from a catalog item can be a sophisticated process, which requires multiple steps to correctly setup....
Create a Workflow
Now, you’ll need to create a workflow that triggers on the submission of the catalog item:
- Navigate to Workflow > Workflow Editor.
- Click on “New” to create a new workflow and select the table the workflow applies to. For catalog items, this will usually be the “Requested Item [sc_req_item]” or “Catalog Task [sc_task]” table.
- Give your workflow an appropriate name that reflects its function.
### 3. Setup the Workflow to Evaluate MRVS
Within the workflow, you’ll need to add logic to iterate through the MRVS rows and determine the necessary approvals based on the variables. Since workflows do not natively iterate through MRVS values, you will likely need to incorporate a script action to do this:
- Use the Run Script activity within your workflow.
- In the script, you will need to decode the MRVS value. This data is stored in JSON format in a variable associated with the request item. Use GlideRecord queries to fetch the request item and its variables. Then parse the JSON to evaluate the conditions for your approvals.
Below is an extremely basic script template to illustrate how you might start:
var gr = new GlideRecord(‘sc_item_option_mtom’); // This table links the variable set to the requested item.
gr.addQuery(‘request_item’, current.sys_id); // ‘current’ is the current requested item in context.
gr.query();
while (gr.next()) {
var json = new global.JSON();
var mrvsValues = json.decode(gr.variables); // Assuming ‘variables’ is storing your MRVS data. Adjust as needed.
// Your logic here to check MRVS values and determine approvals
}
Note: This script is highly simplified. You will need to tailor it to how your MRVS and individual variables are structured.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 02:57 AM
Hello Deepak,
Above solution to trigger approval based MRVS values on the catalog item. Based on individual MRVS value triggering approval in ritm request right. I am correct.