How to update next record field value based on previous record field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 08:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 06:24 AM
Hi @Deepak92 , please try below script in your on after business rule.
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
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 07:18 AM
Hi @Deepak92
you can write after insert BR and in the script check if there is already a record with the same ticket ID and status is not empty then update the current record with existing record sub status.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 07:32 AM
Hello @priyasunku ,
How do i check whether previous records having status (clsoed_Redirect ) ?? and then i need to set current record field.
i don't need to update previous record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 07:31 AM
Hi @Deepak92 , Thank you for the clearing the requirement.
I will suggest you to create one After Insert BR on respective table.
e.g. I have consider Incident table here.
And use below Script
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var ticketId = current.u_ticket_id;
var gr = new GlideRecord('incident');
gr.addQuery('u_ticket_id', ticketId);
gr.addEncodedQuery("u_biznow_sub_status=closed _redirect");
gr.query();
if (gr.next()) {
//gs.addInfoMessage("Record found with same ticket Id and status is closed _redirect");
current.u_biznow_sub_status = 'closed _redirect';
current.update();
}
//Note:
//1] Here 'u_ticket_id' is a field name of 'Ticket Id' field
//2] 'u_biznow_sub_status' is a field name of 'BizNow Sub Status' field and 'closed _redirect' is choice of this field.
//3] Here 1st query to check same ticket id exists or not and 2nd one is to check its status is closed _redirect.
//Kindly change the Table Name and fields name accordingly.
})(current, previous);
Let us know if you are facing any issue
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 08:58 AM
Hello @Sonu Parab ,
Thanks for the revert.
current.update is not recommended on after BR . correct ? it may run again and again and create performance issues.
what if i declare current value in variable and then update them. will it also going to create performance issue like which current.update used to create .just want to cross check with you