- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 04:54 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 05:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 05:19 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 05:23 AM
Hi @_Samay
Refer to the below link
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 05:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 01:50 AM
Hi @Amitoj Wadhera - Thanks for your valuable reply. It's really working amazing.