- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2015 01:11 AM
Hi All,
Need to display all active incident's - incident number, username and email. But couldn't get the expected output. can anyone tell whats wrong with the code.
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
//gs.addInfoMessage("first");
var inc = new GlideRecord('incident');
inc.addQuery('active',true);
inc.query();
while (inc.next()) {
gs.addInfoMessage(inc.number);
var grpMbr = new GlideRecord('sys_user');
grpMbr.addQuery('user_id', inc.caller_id);
grpMbr.orderByDesc('sys_created_on');
grpMbr.query();
while (grpMbr.next()) {
var emailid = grpMbr.email;
var userid = grpMbr.user_name;
gs.addInfoMessage(userid +" = "+emailid);
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2015 02:09 AM
Hi Anto,
Running this script in Background Scripts produces the result you want:
var inc = new GlideRecord('incident');
inc.addQuery('active',true);
inc.query();
while (inc.next()) {
gs.print(inc.number);
gs.print(inc.caller_id.getDisplayValue());
var grpMbr = new GlideRecord('sys_user');
grpMbr.addQuery('sys_id', inc.caller_id);
grpMbr.orderByDesc('sys_created_on');
grpMbr.query();
while (grpMbr.next()) {
var emailid = grpMbr.email;
gs.print(emailid);
}
}
I don't understand why you would use this in a business rule with gs.addInfoMessage, especially if output is large.
Second, in the sys_user GlideRecord call, don't use user_id in addQuery, but sys_id, as inc.caller_id is actually sys_id of sys_user record.
Does this helps? Otherwise please explain a bit more into details what you want to achieve.
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2015 01:19 AM
Hi Anto,
How are you applying this script?
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2015 01:31 AM
using Business rule in incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2015 01:48 AM
Hi Anto,
This works for me as a business rule on display with a condition:
Condition:
current.active == true
Script:
function onDisplay(current, g_scratchpad) {
//This function will be automatically called when this rule is processed.
gs.addInfoMessage(current.number);
gs.addInfoMessage(current.caller_id.getDisplayValue());
var grpMbr = new GlideRecord('sys_user');
grpMbr.addQuery('sys_id', current.caller_id);
grpMbr.query();
while (grpMbr.next()) {
var emailid = grpMbr.email;
gs.addInfoMessage(emailid);
}
}
Screenshot:
Regards,
Sergiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2015 02:00 AM
Sergiu thanks for the reply, I need all the active records of incidents , not only for the current.caller_id and for all the caller_id for active incidents.