- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2017 06:55 AM
having a brain malfunction
Need to capture, in metric definitions, the user that has added a work note AND the user is a member of a specific team
HELP!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2017 05:03 AM
we have a weiner...
With help from @mohammed.ali at Hi Support we have matched the user updating to users in the group members table. We now have a winning script:
var s = current.task; //Incident being updated
var t = current.sys_updated_by; //user adding work note
var p = new GlideRecord ('sys_user');
var b;
p.addQuery('user_name',t);
p.query();
while (p.next()){
b = p.sys_id;
}
var m = new GlideRecord ('sys_user_grmember');
m.addQuery('user',b);
m.addQuery('group.name','STARTSWITH', 'Your team name prefix here');
m.query();
if (m.next()){u=true;}
else u=false;
gs.log('MTRC ref number here: '+u);
if (u == true){
gs.log('Execute script createMetric: MTRC ref number here '+ '. Work Note added by: '+ t + ' a member of Your team name prefix here.');
createMetric();
}
else{
gs.log('Do NOT execute script createMetric: MTRC ref number here '+ '. Work Note added by: '+ t + ' NOT a member of Your team name prefix here.');
}
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.value = t;
gr.calculation_complete = true;
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 01:06 AM
The isMemberOf uses the name of the group not the sys_id.
gs.getUser gets your logged in user, try adding worknotes with different users ones that are members of the group and others that are not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 01:13 AM
I've tried with the sys_id and team name but neither are working. I've
actually spoken with HI support and there maybe an issue with isMemberOf so
they are investigating further as it maybe an issue with it working with
createmetric.
On 12 January 2017 at 09:07, melghi <community-no-reply@servicenow.com>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 06:06 AM
That's interestring, what version of ServiceNow are you working on?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 07:21 AM
Helsinki patch 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2017 05:03 AM
we have a weiner...
With help from @mohammed.ali at Hi Support we have matched the user updating to users in the group members table. We now have a winning script:
var s = current.task; //Incident being updated
var t = current.sys_updated_by; //user adding work note
var p = new GlideRecord ('sys_user');
var b;
p.addQuery('user_name',t);
p.query();
while (p.next()){
b = p.sys_id;
}
var m = new GlideRecord ('sys_user_grmember');
m.addQuery('user',b);
m.addQuery('group.name','STARTSWITH', 'Your team name prefix here');
m.query();
if (m.next()){u=true;}
else u=false;
gs.log('MTRC ref number here: '+u);
if (u == true){
gs.log('Execute script createMetric: MTRC ref number here '+ '. Work Note added by: '+ t + ' a member of Your team name prefix here.');
createMetric();
}
else{
gs.log('Do NOT execute script createMetric: MTRC ref number here '+ '. Work Note added by: '+ t + ' NOT a member of Your team name prefix here.');
}
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.value = t;
gr.calculation_complete = true;
gr.insert();
}