send survey after every 10 closed incident?

ash36
Kilo Contributor

I need to send incident survey on repeated interval of 10 incident closure. I tried setting the trigger condition based on Number ends with 0, but that's not a concrete solution. Has anyone done this before?

Help much appreciated, thanks !

27 REPLIES 27

Rakesh Mamidi
ServiceNow Employee
ServiceNow Employee

For exact count of 10,You write a script include like below and call the script include in the trigger business rule condition.




var checkCount = Class.create();


checkCount.prototype = {


  initialize: function() {


  this.frequency = 10;


  },




  checkTaskCount : function()


  {


  var lastTriggerID = this.lastSurveyTakenFor(incident,'87186844d7211100158ba6859e610378'); //Table Name and Metric type.


  if(lastTriggerID){


  var inc = new GlideRecord('incident');


  inc.get(lastTriggerID);


  var closedAt = inc.closed_at;


  var incident =   new GlideRecord('incident');


  incident.addNotNullQuery('closed_at');


  incident.addQuery('closed_at','>=',closedAt);


  incident.orderByDesc('closed_at');


  incident.chooseWindow(this.frequency-1,this.frequency);


  incident.query();


  if(incident.next()){


  return true;


  }


  else{


  return false;


  }


  }


  return true;


  },




  lastSurveyTakenFor : function(tableName,metricType)


  {


  var gr = new GlideRecord('asmt_assessment_instance');


  gr.addQuery('trigger_table',tableName);


  gr.addQuery('metric_type',metricType);


  gr.addQuery('trigger_id','!=','');


  gr.query();


  if(gr.next())


  {


  return gr.trigger_id;


  }


  else


  {


  return false ;


  }


  },





  type: 'checkCount'


};


Thanks Rakesh,



I'll test and update you. Just to confirm, if i change 'this.frequency = 10;' to 'this.frequency = 3;' , the survey will send after every 3 incidents? Also, when you say "call the script include in the trigger business rule condition.", it means the business rule that is set in the trigger condition? Right now I have this setup in my BR script:


function onAfter(){


(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, 'e127cb9adb843a00d4385540cf961987');


}



Do I need to remove it and just call the script Include?



Thanks in advance!!


Rakesh Mamidi
ServiceNow Employee
ServiceNow Employee

Yes, Changing frequency will do.



Don't change any thing in the script.But in BR condition call script include as new checkCount().checkTaskCount();


Hi Rakesh,



It's sending after every closed incident. Here is my trigger condition:


find_real_file.png


and here is BR:


find_real_file.png


Thanks,


Ashish


Rakesh Mamidi
ServiceNow Employee
ServiceNow Employee

What is the metric type you are passing in the script include? Is it same sys_id of your survey?