6 Replies · Latest reply on Dec 29, 2017 10:52 AM by Lisa Rugen

    Looking for a metrics from assignment group to assigned to

      Hi , my requirement is get duration from the time 'assignment group' is filled  to 'assigned to'.


      I am looking at metric>definition> Assigned to duration, Assignment group. but i am not able to combine two definitions to pull required report.  am I looking at correct place?  pull


      is there any other way to fullfil my requirement? please help.




        • Re: Looking for a metrics from assignment group to assigned to

          are you saying that you are looking for time

          elapsed between last updated Assignment group with empty and first "Assigned to" value.

          can you explain your requirement again

          In order to help others with this information Please Hit Like, Correct Or Helpful depend upon level of response
          How to Mark Answer as Correct: https://community.servicenow.com/docs/DOC-5601

          • Re: Looking for a metrics from assignment group to assigned to
            aniket gore

            You will have to create a custom metric with below logic,


            1) Custom Script duration metric

            2) Fires on the Assigned to change

            3) Query the metric table with definition = assignment group and metric.value = current.assignement_group

            4) Pull the start time from the record found in the step 3 and calculate time diff between start time and current time. This is your elapsed time.


            Hope this helps.

              • Re: Looking for a metrics from assignment group to assigned to
                Lisa Rugen

                Hi Aniket-

                I understand the steps required, but I'm struggling to execute it. Do you have code examples/screenshots you can share?


                Thanks in advance


                • Re: Looking for a metrics from assignment group to assigned to
                  santhoshi jaini

                  Hi aniket


                  Could you explain me in more detail




                    • Re: Looking for a metrics from assignment group to assigned to
                      Lisa Rugen

                      Hi Santhoshi-

                      I was able to come up with something so I will share it with you.


                      1) I created a Metric Definition called 'Time to Assigned To' off the Task table. It is Type=script calculation and it has no script. it is just a shell used by a business rule.


                      2) I then created a 'Metrics - Time to Assigned To' business rule that fires under the conditions we wanted, any requested item, incident or sc_task record.




                      On the advanced tab we entered the following script:


                      (function executeRule(current, previous /*null when async*/) {


                      if(previous.assigned_to =='' && current.assigned_to!='') {

                        //if assigned to went from blank to something

                          //gs.log("B1: " + current.number);



                      else if (((previous.assignment_group!=current.assignment_group) && current.assigned_to!='')){

                      // the assignment group changed and it was assigned in one action

                           //gs.log("B2: " + current.number);




                      function insertMetrics(chgtype) {

                        //create a record recording time to assignment to a peep

                        var t='';

                        var x=new GlideRecord('metric_instance');

                        x.addQuery('definition','=','e15e7db3056c6900d0771d8b82f882f4');//Assignment Group Duration - Task

                        x.addQuery('value','=',current.assignment_group.getDisplayValue()); //current assignment group

                        x.addQuery('calculation_complete','=','false'); //metric is still active

                        x.addQuery('id','=',current.sys_id);//this ticket


                        while (x.next()){

                         t=x.sys_created_on; //this would be the date/time the metric for assignment group was created.





                        //no assigngroup metric exists so check to see what type of change was made on the ticket

                         if (chgtype==1){

                          //grab the date the date the ticket was created because it may have come in via a catalog item and the assigngroup metric was not created.



                         else if (chgtype==2) {

                          //if yes assume ticket was assigned to another group and assigned out at the same time this did not populate





                        var mi= new GlideRecord('metric_instance');

                        //sys id of the metric definition

                        var metricSysID = '0ad9a01a1313f2408498bd122244b00f';


                        mi.definition = metricSysID;

                        mi.start = t;

                        mi.end = gs.nowDateTime();

                        mi.duration = gs.dateDiff(mi.start, mi.end);

                        mi.id = current.sys_id;

                        mi.field_value = current.assignment_group.getDisplayValue();

                        mi.calculation_complete = true;



                        gs.log("creating time to assigned to metric: " & current.number);



                      })(current, previous);



                      I believe that is all you need, but it's been awhile since I looked at it so if that doesn't work let me know and I'll dig further to see what I forgot to share.


                      Hope this helps!