Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Copying description field without html tags

Suvetha S
Tera Contributor

Hi All,

We have a BR that populates rich description from a record producers variables. We want the same to be copied into description field as well but without HTML tags. I have tried the below script and it is not working as expected. Please provide your suggestions.

 

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

/* Created as part of requirement:  where the Record Producer fields needs to be copied to HR Task Description */
var totalDescription = '';
var newDescription = '';
var grQuestion = new GlideRecord("question_answer");
grQuestion.addEncodedQuery("table_sys_id=" + current.sys_id);
grQuestion.orderBy('order');
grQuestion.query();
while (grQuestion.next()) {
if (grQuestion.question.type == '8' && grQuestion.question.reference != '') {
totalDescription += '<b>' + grQuestion.question.getDisplayValue() + ' : ' + '</b>' + getValue(grQuestion.value, grQuestion.question.reference) + '<br><br>';
}
else if (grQuestion.question.getDisplayValue() == '') {
totalDescription += "<b>----------------------------------------------------------------------------------------------</b><br><br>";
}
else {
totalDescription += '<b>' + grQuestion.question.getDisplayValue() + ' : ' + '</b>' + grQuestion.value + '<br><br>';
newDescription += grQuestion.question.getDisplayValue() + ' : ' + grQuestion.value ;
}
}
function getValue(id, table) {
var grDetails = new GlideRecord(table);
if (grDetails.get(id)) {
return grDetails.getDisplayValue();
} else { return ' '; }
}
var hrTask = new GlideRecord('sn_hr_core_task');
hrTask.get(current.sys_id);
hrTask.rich_description = 'The following details have been provided:' + '<br><br>' + totalDescription;
hrTask.description = 'The following details have been provided:' + newDescription;
hrTask.update();


})(current, previous);

2 REPLIES 2

Markus Nilsson
Tera Guru

Hi,
Not a solution for your script but can't you just create a "dummy" variable thats not visible on your record producer that capture all info and then map that to the field?

/Markus

Best regards,
Markus Nilsson
+46709389974

Saurabh Gupta
Kilo Patron

Hi,

You can do as per below script 

 

var vs = new GlobalServiceCatalogUtil().getVariablesForTask(tr, true);      //tr is the GlideRecord object of the target task  
var notes="";
var notesHTML="";
for (var i=0; i < vs.length; i++)
{
    
    var isMRVS=lbl=vs[i].multi_row+"";
    var lbl=vs[i].label+"";
    var dis=vs[i].display_value+"";
    var visible=vs[i].visible_summary+"";
    if(isMRVS=='true')
    {
        var vArr=vs[i];
        notes+= lbl +"\n";
        for (var j=0; j < vArr.table_variable.length; j++)
        {
            notes+="Row " + (j+1)  + "\n";
            var tblArr=vArr.table_variable[j];
            for (var k=0; k < tblArr.length; k++)
            {
                var mrvslbl=tblArr[k].label+"";
                var mrvsdis=tblArr[k].display_value+"";
if(mrvslbl != '' && mrvsdis!='' && mrvsdis!='false') 
					{
                notes+= mrvslbl +  ": " + mrvsdis + "\n";
              notesHTML+=  "<div>"  + "<strong>" + mrvslbl + "</strong>" + ": " + mrvsdis + "</div>";
            }
}
            notes+= "\n";
        }
    }
    else
    {
        if (lbl != '' && dis!='' && dis!='false' && visible=='true') {
            notes+=lbl + ": " + dis + "\n";
notesHTML+="<div>"  + "<strong>" + lbl + "</strong>" + ": " + dis + "</div>";
        }
    }



}

//notesis the simple text field with all the variables in it
//notesHTML is the HTML field with all the variables in it

 

 

 


Thanks and Regards,

Saurabh Gupta