Usecase related to incident

Pratik232
Tera Contributor

Display a list of incidents as per logged in user's location with incident location.

I have trying this use case in query business rule , but it not getting desired output as expected.

I have tried Background script in that its working fine but in incident table its not working.

 

var userLocation = gs.getUser().getLocation();

if (!userLocation) return;

current.addQuery('location', userLocation);

 

 

3 REPLIES 3

UmesH77
Tera Expert

Hello @Pratik232 , 

I have tried using this code . It will working in that .

 

Here's is the code .

(function executeRule(current, previous /*null when async*/ ) {

// Add your code here
var current_user = gs.getUserID();

var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', current_user);
usr.query();
if (usr.next()) {
current.addQuery('location=' + usr.location);
}
})(current, previous);

if my response is helpfull please mark it as helpfull,🙏 and accept as a solution👍
 
Regards,
UmesH.

Screenshot 2026-01-09 115841.pngScreenshot 2026-01-09 115858.png

Ankur Bawiskar
Tera Patron

@Pratik232 

Remember there is already 1 OOTB query BR on incident table

If you are doing this for learning purpose then your query BR is correct

Please disable the OOTB one and then test

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

adityahubli
Tera Guru

Hello @Pratik232 ,

 

Try This before Query Business Rule Code snippet :

 

(function executeRule(current, previous /*null when async*/ ) {

    var ga = new GlideRecord('sys_user');
    if (ga.get(gs.getUserID())) {
        current.addQuery('location', ga.location);
        current.query();
    }
})(current, previous);

 

Screenshot 2026-01-09 123259.png

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

technical Consultant