Writing Results From MRVS to Description Field

jmiskey
Kilo Sage

We currently have a Record Producer which creates a Safe Epic record that gets sent over to Azure DevOps.  Basically, we write out all the field values entered on the Record Producer to the Description field (as straight text) so it gets sent over to AzDo.

 

So, for example, we may have the following variables on the Record Producer:

- Submitter (submitter)

- Short Description (short_description)

- Executive Summary (executive_summary)

 

Then, in the Script section of the Record Producer, we capture these values and write them out to the HTML Description field of the Safe Epic like this:

 

//capture values from variables
var submitBy = producer.submitter.name;
var shortDesc = producer.short_description;
var execSumm = producer.executive_summary;

//write to HTML Description field of Safe Epic
current.html_description = 
'<b> Submitter : </b>' + submitBy + '<br>'+
'<b> Short Description : </b>' + shortDesc + '<br>'+
'<b> Executive Summary  : </b>' + execSumm + '<br>';

This all works very well.

 

However, I have a new twist.  We have a Multi-Row Variable Set (MRVS) that is on this Record Producer.  I am not sure how to capture the values from this MRVS and write to the HTML Description field, especially since we do not know how many records there will be in the MRVS.

 

My MRVS looks like this:

jmiskey_0-1744717122061.png

 

So the completed MRVS on the Record Producer may look like this, for example:

ArrangementDescription
Fully InsuredSome description here
Self FundedSome other description here
PooledSomething else here

 

Can anyone provide some guidance on how I would update my Script to capture these values from the MRVS and write them to the HTML Description field?

 

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jmiskey 

parse the MRVS json and iterate and concatenate

Something like this and enhance

// Capture values from variables
var submitBy = producer.submitter.name;
var shortDesc = producer.short_description;
var execSumm = producer.executive_summary;

var json = producer.group_funding_arrangement; // Replace with your actual MRVS variable name
var parsedData = JSON.parse(json);

var mrvsData = '<table border="1" style="border-collapse: collapse;"><tr><th>Arrangement</th><th>Description</th></tr>';
for (var i = 0; i < parsedData.length; i++) {
    var rowData = '<tr><td>';
    var arrangementSysId = parsedData[i].arrangement;
    var gr = new GlideRecord("tableName"); // Replace "tableName" with the actual table name
    gr.addQuery("sys_id", arrangementSysId);
    gr.query();
    if (gr.next()) {
        rowData += gr.getDisplayValue() + '</td>';
    }
    rowData += '<td>' + parsedData[i].description + '</td></tr>';
    mrvsData += rowData;
}
mrvsData += '</table>';

// Write to HTML Description field of Safe Epic
current.html_description =
    '<b> Submitter : </b>' + submitBy + '<br>' +
    '<b> Short Description : </b>' + shortDesc + '<br>' +
    '<b> Executive Summary : </b>' + execSumm + '<br>' + mrvsData;

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@jmiskey 

parse the MRVS json and iterate and concatenate

Something like this and enhance

// Capture values from variables
var submitBy = producer.submitter.name;
var shortDesc = producer.short_description;
var execSumm = producer.executive_summary;

var json = producer.group_funding_arrangement; // Replace with your actual MRVS variable name
var parsedData = JSON.parse(json);

var mrvsData = '<table border="1" style="border-collapse: collapse;"><tr><th>Arrangement</th><th>Description</th></tr>';
for (var i = 0; i < parsedData.length; i++) {
    var rowData = '<tr><td>';
    var arrangementSysId = parsedData[i].arrangement;
    var gr = new GlideRecord("tableName"); // Replace "tableName" with the actual table name
    gr.addQuery("sys_id", arrangementSysId);
    gr.query();
    if (gr.next()) {
        rowData += gr.getDisplayValue() + '</td>';
    }
    rowData += '<td>' + parsedData[i].description + '</td></tr>';
    mrvsData += rowData;
}
mrvsData += '</table>';

// Write to HTML Description field of Safe Epic
current.html_description =
    '<b> Submitter : </b>' + submitBy + '<br>' +
    '<b> Short Description : </b>' + shortDesc + '<br>' +
    '<b> Executive Summary : </b>' + execSumm + '<br>' + mrvsData;

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

That works beautifully!

Thank you, Ankur!

@jmiskey 

Glad to help.

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