Multirow variable data to description of HR case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2024 01:40 AM
Hi experts,
How can we populated multirow variable data on record producer to the generated HR case description ?
Please provide me your suggestions
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2024 02:11 AM - edited ‎06-14-2024 02:29 AM
Hi @si21 ,
To populate multi-row variable data on a record producer to the generated HR case description in ServiceNow, you can follow these steps:
Create the Multi-Row Variable Set:
- Define a multi-row variable set in your catalog item or record producer.
- Add the necessary variables to this multi-row variable set.
Define the Record Producer:
- Create a record producer for your HR case.
- Include the multi-row variable set you created in the record producer.
Script to Populate HR Case Description:
- Use a script in the "Script" field of the record producer or in a business rule to retrieve the data from the multi-row variable set and format it into the HR case description.
Here's a step-by-step guide with sample code:
Step 1: Create Multi-Row Variable Set
- Navigate to Service Catalog > Catalog Definition > Maintain Items.
- Select or create the catalog item/record producer.
- Scroll down to the "Variable Sets" related list and click "New".
- Choose "Multi-Row Variable Set" and define the variables.
Step 2: Create Record Producer
- Navigate to Service Catalog > Catalog Definitions > Record Producers.
- Click "New" and fill in the details for your HR case record producer.
- Under the "Variables" tab, include your multi-row variable set.
Step 3: Script to Populate HR Case Description
In the "Script" field of the record producer, you can write a script to process the multi-row variable data. Here is a sample script:
(function() {
// Retrieve the record producer variables
var gr = current; // 'current' is the record producer record
// Initialize a description string
var description = 'HR Case Description:\n';
// Retrieve the multi-row variable set
var multiRowVariableSet = gr.variables.multi_row_variable_set_name; // Replace with your multi-row variable set name
// Iterate over each row in the multi-row variable set
for (var i = 0; i < multiRowVariableSet.getRowCount(); i++) {
var row = multiRowVariableSet.getRow(i);
description += '\nRow ' + (i + 1) + ':\n';
// Iterate over each variable in the row and append to description
for (var field in row) {
if (row.hasOwnProperty(field)) {
var variable = row[field];
description += variable.getLabel() + ': ' + variable + '\n';
}
}
}
// Set the description field on the HR case
gr.description = description;
// Optionally, set other fields or take additional actions
// gr.short_description = 'HR Case Created from Record Producer';
// gr.category = 'HR Category';
// gr.insert(); // If you need to insert the record manually
})();
Explanation
- Retrieve Record Producer Variables: The current object represents the record producer record.
- Initialize Description: Start with an initial description string.
- Retrieve and Iterate Multi-Row Variable Set: Access the multi-row variable set and iterate over each row.
- Append Each Variable to Description: For each variable in the row, append its label and value to the description string.
- Set Description: Assign the constructed description to the HR case's description field.
Deploy the Script
- Place the script in the Script field of the record producer.
- Test the record producer by filling in the multi-row variables and submitting the form.
- Verify that the HR case is created with the correctly formatted description.
Additional Considerations
- Security and Permissions: Ensure the script has the necessary permissions to access the variables and set fields on the HR case.
- Error Handling: Add error handling to manage cases where variables might be empty or missing.
- Performance: For large datasets, consider optimizing the script for better performance.
By following these steps, you can successfully populate multi-row variable data from a record producer into the HR case description in ServiceNow.
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 06:07 AM
Hi Astik, I tried this code and description is not getting populated. It is empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2024 02:34 AM
in the record producer script; access the MRVS i.e. json; parse it and populate
something similar to this; but enhance it
How to transfer a multi-row variable set from a record producer to a case form
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2024 02:35 AM - edited ‎06-14-2024 02:35 AM
HI @si21 Write a script like this in Record Producer Script field
var mvrs = JSON.parse(producer.mrvs_Name);
var desc1 = '';
for (var i = 0; i < mvrs.length; i++) {
desc1 += "MRVS variable 1 # " + " : " + mvrs[i].mrvs_variable_1 + " MRVS variable 2 # " + " : " + mvrs[i].mrvs_variable_1 + " MRVS variable 3 #" + " : " + mvrs[i].mrvs_variable_3 + '\n';
}
current.description = desc1;
The above script will populate MRVS data to Description field like below
Regards,
Sid