- 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-10-2017 12:54 PM
ah ha, got it
// if (mi.metricExists())
// return;
comment this out and working as needed, brill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 01:22 PM
so, can not get the users full name as sys_updated_by is not a reference field in incident, so it will have to do. Therefore we are left with this script working as needed:
var s = current.task; //Incident being updated
var t = current.sys_updated_by; //user adding work note
if (gs.getUser().isMemberOf("UK&ROI - Level 2 - Corporate"));
createMetric();
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-10-2017 11:59 PM
Why do you prefer working with
var t = current.sys_updated_by; //user adding work note
instead of
var t = gs.getUser(); ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 01:02 AM
bcoz the users name is not brought back when using gs.getUser();
I'd love to be able to use it this so I can get the full user name but it just return 'system'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2017 02:07 AM
grr it looks like the isMemberOf isn't working now, it's actually creating an record for everyone adding a work note, neither of these seem to work
if (gs.getUser().isMemberOf("UK&ROI - Level 2 - Corporate"));
if (gs.getUser().isMemberOf("5f5d736f37a2c200dd95db9643990e34"));