- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2014 05:48 AM
Hi
I have an issue with my metric definition script.
The metric does not work and I'm not sure if I used the not null condition check correctly, or something else is wrong. Even if a try null, 'NULL', or "NULL" it does not work.
I would like the metric to fire when the u_root_cause_ci field is populated for the first time.
Can anyone help?
if(current.u_root_cause_ci != 'NULL'){
createMatricx(current);
}
function createMatricx(current) {
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.duration = gs.dateDiff(gr.start, gr.end);
gr.calculation_complete = true;
gr.insert();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2014 06:58 AM
yes, sounds like it try printing what it sees as a value right at the start..
gs.log(current.u_root_cause_ci);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2014 05:59 AM
You can just use if(!current.u_root_cause.nil())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2014 06:13 AM
Thanks for your comment mguy, unfortunately the proposed solution is not working. Any idea what can be wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2014 06:24 AM
I would add a couple of gs.log statements into your script to see how far your getting, because some condition must not be getting satisfied. ie.
if(!current.u_root_cause_ci.nil()){
gs.log('current roots cause is empty - attempting to create Matricx','matrix.definition');
createMatricx(current);
}
function createMatricx(current) {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
gs.log('metric exists already so stopping','matrix.definition');
return;
gs.log('attempting to insert record','matrix.definition');
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.duration = gs.dateDiff(gr.start, gr.end);
gr.calculation_complete = true;
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2014 06:47 AM
I have updated the script and updated a relevant record, but couldn't find any of the above log entries in the Script Logs. So it means that the if condition check fails, right?