- 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 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 02:34 AM
tried it in addInfoMessage to check whether its working, gonna apply this for some other scenario
thanks Sergiu.