Copy RITM variables to sc_task worknotes

varma2
Mega Sage

Hi All,

 

I have requirment which need  to copy the all RITM varibles to sc_task worknotes.

 

Could you please help on this to achive the requirment.

 

Thanks all,

Varma

1 ACCEPTED SOLUTION

@varma2 Please try below updated code. It will fix the issues.

 

var ritm = new GlideRecord("sc_req_item");
if(ritm.get(current.request_item.toString())){
var itemOption = new GlideRecord("item_option_new");
itemOption.addQuery("cat_item="+ritm.cat_item.toString());
itemOption.addQuery("nameISNOTEMPTY");
itemOption.orderBy("order");
itemOption.query();

var workNotes = "";
while(itemOption.next()){
workNotes += itemOption.question_text.toString() +" : "+ritm.variables[itemOption.name.toString()].getDisplayValue()+"\n";

}

current.work_notes = workNotes;
}
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

24 REPLIES 24

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @varma2 

Create before insert business rule in sc_task table as below :Script :--

 

// Get the sys_id of the related RITM record

var ritmSysId = current.request_item.sys_id;

 

// Get the RITM record

var ritm = new GlideRecord('sc_req_item');

ritm.get(ritmSysId);

 

// Initialize an array to hold the variable names and values

var variables = [];

 

// Loop through all the variables in the RITM record

ritm.variables.variables.forEach(function(variable) {

   // Add the variable name and value to the array

   variables.push(variable.getName() + ': ' + variable.getValue());

});

 

// Concatenate the array into a single string

var workNotes = variables.join('\n');

 

// Set the work notes field of the sc_task record

current.work_notes = workNotes;

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar 

I was implimented the code but its not working, variables not copy to the work notes on sc_task. even i was try to give decription it's not copying variables

please suggest.

 

Thanks,

Varma

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,

You can write the below code in workflow/flow or you can write a on Before insert BR (If you need this functionality for all catalogs)

var vs = new GlobalServiceCatalogUtil().getVariablesForTask(tr, true);      //tr is the GlideRecord object of the target task here it is RITM GlideRecord object  
var notes="";
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";
          
            }
}
            notes+= "\n";
        }
    }
    else
    {
        if (lbl != '' && dis!='' && dis!='false' && visible=='true') {
            notes+=lbl + ": " + dis + "\n";

        }
    }



}

//notes is the variable that contains all the variables with its values including multi row variable set.

 

 


Thanks and Regards,

Saurabh Gupta

Hi Saurabh,

 

I was implimented the code but its not working, variables not copy to the work notes. please suggest.

 

Thanks,

Varma