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.

Need to populate the free text value to the one of the reference field in the Incident table

vinuth v
Tera Expert

Hi All,

 

I am working on the Record producer form, My requirement is on the form level I have one field called "Please provide the ADO/Change number associated with the previous change." it is a single line text field and I wanted to updated this field value to the "Caused by Change" OOB field in the incident table and it is a reference field and referring to change_request table.

 

Note : 

Please provide the ADO/Change number associated with the previous change backend value is ado_change

Caused by Change backend value is caused_by

 

I tried like this in the Record Producer script,

vinuthv_0-1713522838134.png

 

In the background script I tried like below,

var gr=new GlideRecord("incident");
gr.addQuery('number''INC0010003');
gr.query();
if(gr.next())
{
    gr.caused_by="chg3344";
    gr.update();
}
 
But It is not working please any one suggest me,
 
Thanks,
Vinuth

 

6 REPLIES 6

Community Alums
Not applicable

Hi @vinuth v ,

As I checked your problem in my PDI I got solution please refer below script

var gr=new GlideRecord("incident");
gr.addQuery('number', 'INC0010003');
gr.query();
if(gr.next())
{
    gr.caused_by='c83c5e5347c12200e0ef563dbb9a7190'; // Sys_id of change record
    gr.update();
}

 

As caused_by is reference field so you need to give the sys_id in that case than it will work

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Redards

Sarthak

Hi @Community Alums 

 

This is working in background script, how to implement in the Record producer Script.

Hi @vinuth v ,

 

Please try the below script in record producer :

var chgRec = new GlideRecord("change_request");
chgRec.addQuery('number', producer.ado_change); //Change number(also implement some validation for this field)
chgRec.query();
if(chgRec.next())
{
    current.caused_by = chgRec.sys_id; //It returns the sys_id of Change record
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Community Alums
Not applicable

Hi @vinuth v ,

Please check below script 

 

 

var gr=new GlideRecord("change_request");
gr.addQuery('number', producer.ado_change);
gr.query();
if(gr.next())
{
    current.caused_by=gr.sys_id; // sys_id of change record
    gr.update();
}

 

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

Please mark my answer correct and helpful if this works fine