Values from multi row variable set not populating in knowledge article

Amol Pawar
Tera Guru

Hi All,

I have a requirement where I need to create a Knowledge article when a form is submitted from a record producer on the portal. I have used a Multi-Row variable set in that record producer so that users can add multiple rows and information as per their need. I want to populate those rows filled by a user in a Knowledge article. I have created a flow which will create a knowledge article once it is approved. To populate record producer values in the knowledge article, I have written an after update Business rule:

 
(function executeRule(current, previous /*null when async*/ ) {
  var body = '';
if ( current.getDisplayValue('sections')){
        body += '<p><b> Sections: ' + '</b>' + current.getDisplayValue('sections') + '</p>';
    }
    if (current.getDisplayValue('section_name_new')){
        body += '<p> ' + current.getDisplayValue('section_name_new') + '</p>';
    }
    if (current.getDisplayValue('information_section_name_new')){
        body += '<p>' + current.getDisplayValue('information_section_name_new') + '</p>';
    }
    current.article_description = body;
    current.update();
})(current, previous);
 
sections - multi-row variable set name
Please help me to populate values filled in multi row variable set in the knowledge article since I'm unable to do this by above business rule as well.
 
Thanks in advance,
Amol
 
6 REPLIES 6

Tai Vu
Kilo Patron
Kilo Patron

Hi @Amol Pawar 

The MRVS is stored value as an Array [Object].

So to get the value in the MRVS, just parse it and loop through each element. Sample below.

Screenshot 2023-11-22 at 12.59.06.png

Screenshot 2023-11-22 at 13.00.18.png

 

So in your case, it will be:

1. Get Value of the MRVS sections.

2. Use JSON.parse to parse the variable.

3. Loop through the array to get value of section_name_new, information_section_name_new, etc. 

 

Cheers,

Tai Vu

Hi @Tai Vu,

 

Thank you for your reply but even after referring to your solution, I'm unable to populate MVRS values in the knowledge Article.

Anything we're missing?

 

Amol

Amol Pawar
Tera Guru

Hi @Tai Vu

Thank you for your response, it worked with a few modifications. We can populate data from multi row variable set now, but it's populating as a text format. Can we make it like populate in a table format?

I'm giving BR script for reference:

 

(function executeRule(current, previous /*null when async*/ ) {

    var body = '<p><b>Sections</b></p>';
    var gr = new GlideRecord('table_name');
    gr.get(current.sys_id);
    gr.query();
    var arrTeam = gr.variables.sections;
    // gs.log('Sections: ' + arrTeam);


    arrTeam = JSON.parse(arrTeam);
    for (var i in arrTeam) {
        body += '<p> ' + '<b>Section Name: </b>' + arrTeam[i].section_name_new + '' + ' <b>Information Section Name: </b>' + arrTeam[i].information_section_name_new + '</br>' + '</p>';

         
    }

    current.article_description = body;
    current.update();
})(current, previous);
 
Please let me know if we can do that.
Thanks,
Amol

Hi @Amol Pawar 

As far as I understand from your scenario is that the section_name_new and information_section_name_new variables are string text (single line text or multiple line text type).

So if you would like to populate into the Article body field with HTML type, you've to add HTML tags beside actual text value.

 

You can leverage the Template [sys_template] to pre-define a HTML template for the article body. Something like below

TaiVu_0-1700720636454.png

Use this API to apply it

applyTemplate(String template)

Then replace the variable ${section_name_new} and ${information_section_name_new} with your own variable's value.

Sample:

var rec1 = new GlideRecord("kb_knowledge");
rec1.initialize();
rec1.applyTemplate("MVRS Template");
rec1.text = rec1.text.replaceAll('${section_name_new}', 'My new name section');
rec1.insert();

 

Btw, why don't you just use the Script box right inside the Record Producer?

TaiVu_1-1700721138113.png

 

Cheers,

Tai Vu