How to get the first related record in the business rule

Santoshi5
Giga Guru

Hi All,

I am stuck in middle, please help me to sort my issue,

for 1 problem if there are 5 incident records are related i want to get the first incident which is related to that problem and want to update some data in to that incident.

Let me know how to add the logic in the filter in business rule so i can get the first record only.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

at which place you are writing this script?

BR? if yes then on which table?

Actually there is no field which can help you determine which incident was first linked with the problem

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Musab Rasheed
Tera Sage
Tera Sage

Hi Santoshi,

Use setLimit(1) before gr.query(); function and that should work.

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

just adding setlimit will not get the exact incident number which is tagged first to that problem, it will give the 1 record not sure if that record is first tagged one or not.

Try like this.?

	var rt = new GlideRecord('incident');
rt.addQuery('problem', current.sys_id);
	rt.orderBy('created_on');
rt.setLimit(1);
rt.query();
while(rt.next())
{
rt.short_description = 'wrtie something';
rt.update();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

at which place you are writing this script?

BR? if yes then on which table?

Actually there is no field which can help you determine which incident was first linked with the problem

regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader