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.

How to update next record field value based on previous record field

Deepak92
Tera Contributor

Hello Folks,

for the same ticket id if  record B has sub status as closed redirect i want to set  record A field value.

Any help would be highly appreciated 

Deepak92_1-1676566051961.jpeg

 

 

 

14 REPLIES 14

Hi @Deepak92 , Change BR when to run condition to Before Insert.

and comment the line current.update();

Hello @Sonu Parab ,

its not worked .

i change before insert

(function executeRule(current, previous /*null when async*/ ) {
gs.info('Start assigned to blank');
var ticketid = current.ticket_id;
var gr = new GlideRecord('XYZ');
gr.addQuery('ticket_id', ticketid);
gr.addEncodedQuery("sub_status_fusion=Closed - Redirect");
gr.query();
if (gr.next()) {

current.fallout_reason = 'Dulicate';
current._status = 'Awaiting Assignment';
current.sub_status_ = 'Fallout';
current.assigned_to = ' ';
}
gs.info('End assigned to blank');
})(current, previous);

 

BR is not triggering.  

Hi @Deepak92 Have you added any condition in When to Run section? and from above BR which gs.info message print?

Swamy Malluri
Tera Guru

Hi @Deepak92 ,

 

Try below logic

 

var tacketId = current.ticket_id; //Give appropriate Ticke Id field name here

var gr = new GlideRecord('incident'); // pass your approprite table name
gr.addQuery('ticket_id', tacketId); // This query to find another same tickid record.
gr.addQuery('number', "!=", current.number); // This query to find another record.
gr.query();
while (gr.next()) {
gr.biznow_sub_status_field = 'Closed - Redirect'; //pass your approriate field name for 'biznow_sub_status_field' and set your logical value of
gr.update();
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thank you

priyasunku
Kilo Sage

Hi @Deepak92 

 

Okay then create before insert BR

var gr = new GlideRecord('table_name');

gr.addEncodedQuery('sub_statusISNOTEMPTY^ticket_id='+current.ticket_id)

gr.query();

if(gr.next()

current.sub_status=gr.sub_status;

 

Please mark this as helpful if your issue is resolved