Record Producer MRVS to HTML Field

sajerond
Tera Contributor

Within a RP, I have a JSON script that parses populates an html field in a custom table which comes from an MRVS.  

I am trying to create a line break and ultimately add a header to the data.  Is this possible with the RP script? 

 

var mRow = producer.add_assets;

var mRowObj = JSON.parse(mRow);
var str = '\n';

for (i = 0; i < mRowObj.length; i++) {
str += mRowObj[i].ip + '|' + mRowObj[i].host + '|' + mRowObj[i].ip_description;
if(i != mRowObj.length -1) {
str += ' | ' ;
}
}

current.u_test_htl_data = str;

 

 

Current Result

sajerond_0-1691536575277.png

 

Ultimate Result

This would be the ultimate result but the line breaks would be acceptable, followed by a header, followed by having all within a table 

 

sajerond_1-1691536820143.png

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Since this is an HTML field, you'll want to use the <br> tag instead of \n, but since you want it in a table, something more like this would work:

var mRow = producer.add_assets;
var mRowObj = JSON.parse(mRow);
var str = '<table><tbody><tr><td><b>IP</b></td><td><b>Host</b></td><td><b>Desc</b></td></tr>';

for (i = 0; i < mRowObj.length; i++) {
    str += '<tr><td>' + mRowObj[i].ip + '</td><td>' + mRowObj[i].host + '</td><td>' + mRowObj[i].ip_description + '</td><tr>';
}

current.u_test_htl_data = str;

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Since this is an HTML field, you'll want to use the <br> tag instead of \n, but since you want it in a table, something more like this would work:

var mRow = producer.add_assets;
var mRowObj = JSON.parse(mRow);
var str = '<table><tbody><tr><td><b>IP</b></td><td><b>Host</b></td><td><b>Desc</b></td></tr>';

for (i = 0; i < mRowObj.length; i++) {
    str += '<tr><td>' + mRowObj[i].ip + '</td><td>' + mRowObj[i].host + '</td><td>' + mRowObj[i].ip_description + '</td><tr>';
}

current.u_test_htl_data = str;

sajerond
Tera Contributor

Thank you Brad.  This is the solution I used.

You are welcome!