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

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,


Thank you very much!. I'll try that.


Instead of an ajax call, you can check whether a user has any open incidents using a display business rule. This way you will have better performance.


That's a very good idea indeed but only for the already opened incidents, because the "display business rule" will take the value when the form will be opened.



As I understood here, we want to help the resolvers / service desk when they are creating new incidents, that means the caller value is changing from a blank value to something.


In that case, only a ajax call could (at my knowledge) do the work



But you're right to make the remark, if someone has to make the same feature at the opening of the form, the "display business rule" will be a better idea.



Regards,