Script to Alert if Caller has active incidentes

jesusemelendezm
Mega Guru

I want to write a script to alert if caller has active incidents so the service desk agent can click on related incidents icon and see what's active for the same caller. What should I be using?

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  var callerName = g_form.getValue('caller');

  var target = new GlideRecord("incident");

 

  if (target.addQuery('caller', callerName) && target.addQuery('active', 'true'))

  {

alert ("Caller has active Incidents, please check related incidents for current caller");

      }

}

1 ACCEPTED SOLUTION

david_legrand
Kilo Sage

Hi Jesus,



Are you sure you don't want to just use the "related incident" icon on the right of the caller field?



If not, I think you should make:


1) not an alert (too invasive frrom my point of view) but a message under the caller field using g_form.showFieldMsg('caller_id','the caller has ' + numberofactiveincident + ' incidents currently active','info');


2) an asynchronous Ajax script to retrieve the information on the server side and send back the number of active incidents of the caller.



You should start by the point 2 (the point 1 is just cosmetic) and I give you this wiki article http://wiki.servicenow.com/index.php?title=GlideAjax


You need to start with "2.1.1.1 Hello World: Returning a value from the server" and don't forget the client side AND server side scripts.


Then, for retrieving on the server side the amount of incidents for the caller, I'm giving you the link http://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/ where you can find getRowCount BUT I'll encourage you to try GlideAggregate (I don't remember where I read that but I think GlideAggregate is a better option for performance perspective)



The last advice with GlideAjax is to start with the wiki example and then to do what you want to do on the server side and then (when the server is sending back the right value) to modify the client side.



Best regards,


View solution in original post

5 REPLIES 5

You are right David. I overlooked the fact that it needed to be done at creation of a new incident.