- 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 07:18 AM
Create a new metric, put in type "Script calculation" , choos ethe table and choose the field worknotes,
and put a script similar to this :
var s = current.task;
if (gs.getUser().isMemberOf(<name oif the group>);
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 07:52 AM
Thanks Mohamed, we're nearly there I think... but it only seems to work once per ticket and I also need to pull the users name into the Value field, any ideas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 08:56 AM
Hi
to get the name gs.value = gs.getUser().getFullName()
Can share with me the content of your metric so I can check the reason it is running just once?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 12:26 PM
So this is what my script currently is, i've gone with var t as it was just giving me 'system' but this gives me the userid:
var s = current.task; //Incident
var t = current.sys_updated_by; //user adding work note is giving the username but it won't give me the full name is I add '.getFullName()' to this object in the below line gr.value = t.getFullName()
if (gs.getUser().isMemberOf("UK&ROI - Level 2 - Corporate"));
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on; //date and time work note added
gr.end = current.sys_updated_on; //date and time work note added
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.value = t; //User who added work note
gr.calculation_complete = true;
gr.insert();
}
So this results in:
So this is what I need BUT it will not add extra entires for the same ID/Incident.
I really appreciate your help with this.