Metric Definition for Scoped App - Duration Between Two Date Fields Not Dependent on State Value

Laurie Marlowe1
Kilo Sage

Hello,

 

I need to create a metric definition based on two date fields.  

When the AD Review field is changed to "Needed" and saved, a business rule puts the Date/Time in the AD Review Start field:

Needed.png

 

When the review is completed, the Reviewer changes the AD Review field to Complete.  A business rule updates the AD Review End field to the current Date/Time:

Completed.png

I'm trying to create a metric instance using this metric definition which is mostly OOB, and I cannot get it to create the metric.  Any ideas?

 

var end = current.ad_review_end;

    if (!end.nil()) {

        createMetric();
    }

    function createMetric() {
        var mi = new MetricInstance(definition, current);
        if (mi.metricExists()) {
            return;
        }
        var gr = mi.getNewRecord();
        gr.start = current.ad_review_start;
        gr.end = current.ad_review_end;
        gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
        gr.calculation_complete = true;
        gr.insert();

    }

 

Thank you,

Laurie

 

1 ACCEPTED SOLUTION

Laurie Marlowe1
Kilo Sage

Found it!  On the original metric definition I forgot to populate the field AD Review End.  Type should be Script Calculation.  And then it worked!

View solution in original post

5 REPLIES 5

Laurie Marlowe1
Kilo Sage

Found it!  On the original metric definition I forgot to populate the field AD Review End.  Type should be Script Calculation.  And then it worked!