MultiRow Variable data collect and store into Rich Text variable

_Samay
Tera Expert

Hi Friends,

We have a multi row variable set and there are 5-6 variables. Whatever data will be selected or entered into MRVS. We would like to prepare a table and store data and set into a Rich Text Field on a table when Request will be submitted from Record Producer.

 

1 ACCEPTED SOLUTION

Amitoj Wadhera
Kilo Sage

Hi @_Samay ,

 

You can write the below code in your record producer script :

 

var htmlTable = '<table border="1" style="width:100%; border-collapse: collapse;">';
htmlTable += '<tr>';
htmlTable += '<th>Variable 1</th>';
htmlTable += '<th>Variable 2</th>';
htmlTable += '<th>Variable 3</th>';
htmlTable += '<th>Variable 4</th>';
htmlTable += '<th>Variable 5</th>';
htmlTable += '</tr>';

var mrvs = producer.multi_row_variable_set_name;
var mrvsData = JSON.parse(mrvs);

for (var i = 0; i < mrvsData.length; i++) {
    var row = mrvsData[i];
    htmlTable += '<tr>';
    htmlTable += '<td>' + row.variable_1 + '</td>';
    htmlTable += '<td>' + row.variable_2 + '</td>';
    htmlTable += '<td>' + row.variable_3 + '</td>';
    htmlTable += '<td>' + row.variable_4 + '</td>';
    htmlTable += '<td>' + row.variable_5 + '</td>';
    htmlTable += '</tr>';
}
htmlTable += '</table>';

current.rich_text_field = htmlTable;
current.update();

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Thanks,

Amitoj Wadhera

View solution in original post

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi @_Samay ,

You can write cliet script in the record producer and read the MRVS, using the JSON.parse() data can be retrive in arraylist and iteration the arraylist and set the values in Rich Text Field.

 

https://www.servicenow.com/community/developer-forum/get-values-from-mrvs/m-p/1864581

https://pathwayscg.com/accessing-multi-row-variable-sets-client-side-in-servicenow/

 

-Thanks,

AshishKM

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

dgarad
Giga Sage

Hi @_Samay 

Refer to the below link

https://www.servicenow.com/community/developer-forum/inserting-data-from-a-multi-row-variable-set-on...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Amitoj Wadhera
Kilo Sage

Hi @_Samay ,

 

You can write the below code in your record producer script :

 

var htmlTable = '<table border="1" style="width:100%; border-collapse: collapse;">';
htmlTable += '<tr>';
htmlTable += '<th>Variable 1</th>';
htmlTable += '<th>Variable 2</th>';
htmlTable += '<th>Variable 3</th>';
htmlTable += '<th>Variable 4</th>';
htmlTable += '<th>Variable 5</th>';
htmlTable += '</tr>';

var mrvs = producer.multi_row_variable_set_name;
var mrvsData = JSON.parse(mrvs);

for (var i = 0; i < mrvsData.length; i++) {
    var row = mrvsData[i];
    htmlTable += '<tr>';
    htmlTable += '<td>' + row.variable_1 + '</td>';
    htmlTable += '<td>' + row.variable_2 + '</td>';
    htmlTable += '<td>' + row.variable_3 + '</td>';
    htmlTable += '<td>' + row.variable_4 + '</td>';
    htmlTable += '<td>' + row.variable_5 + '</td>';
    htmlTable += '</tr>';
}
htmlTable += '</table>';

current.rich_text_field = htmlTable;
current.update();

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Thanks,

Amitoj Wadhera

Hi @Amitoj Wadhera - Thanks for your valuable reply. It's really working amazing.