Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

copy mrvs fields to html field on change request form

Omer Revach
Giga Contributor

Hello 

I have multi row on RP and i need copy mrvs details to html field . i try it but it's not working .

i create BR that run after the change request state is open .

this is the code:

(function executeRule(current, previous /*null when async*/ ) {
    var q1;
    var q2;
    var q3;
    var q4;
    var str = '<table><tbody><tr><td><b>Risk name</b></td><td><b>Likelihood of detection</b></td><td><b>Likelihood of occurrence<br></b></td><td><b>Severity impact</b></td></tr>';
    var gr = new GlideRecord("sc_multi_row_question_answer");
    gr.addEncodedQuery('parent_id=' + current.sys_id);
    gr.orderBy('row_index');
    gr.query();
    while (gr.next()) {
        //str += '<tr>';
   if (gr.item_option_new == '7f90a61587801e10e210eb170cbb359a') {
            //  q1 = gr.value.getDisplayValue();
            q1 = gr.value;
            str += '<td>' + q1 + '</td>';

        }
        if (gr.item_option_new == 'b2646a5987801e10e210eb170cbb357d') {
            q2 = gr.value;
            str += '<tr><td>' + q2 + '</td>';

        }
   
        if (gr.item_option_new == 'ac116e1587801e10e210eb170cbb35fd') {
            q3 = gr.value;
            str += '<td>' + q3 + '</td>';
        }
        if (gr.item_option_new == '49f42e1d87801e10e210eb170cbb357d') {
            q4 = gr.value;
            str += '<td>' + q4 + '</td></tr>';
        }
        //str += '</n>';
        // str += '<td>' + q1 + '</td>' + '<td>' + q2 + '</td>' + '<td>' + q3 + '</td>'+ '<td>' + q4 + '</td>';

    } //str += '</tbody></table>';
 

After i enter value on mrvs and submit the change request the details messed up on html field and the value are not in their row/columnWhatsApp Image 2024-10-14 at 16.22.08.jpegWhatsApp Image 2024-10-14 at 16.24.46.jpegWhatsApp Image 2024-10-14 at 16.24.09.jpeg . what am i do wrong ?



    current.u_risk = str;
    current.update();
1 REPLY 1

Sumanth16
Kilo Patron

Hi @Omer Revach .

 

Refer below code and replace with your variable names.

var arr = producer.mrvs_name;
var desc = '<table border="1px"><tbody><tr><th>Social Impact Assessment</th><th>Entrepreneur Thinking</th><th>Digital Inclusion</th></tr>';
for (var i = 0; i < arr.getRowCount(); i++) {
    desc += '<tr><td>' + arr.getRow(i).social_impact_assessment + "</td><td>" + arr.getRow(i).entrepreneur_thinking + "</td><td>" + arr.getRow(i).digital_inclusion + "</td></tr>";
}
desc += '</table>';

var keywrd = new GlideRecord('table name');
keywrd.initialize();
keywrd.setValue('u_keywords', desc);
keywrd.insert();

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda