Create a generic alert message on the user table

SMuir
Mega Guru

Can someone help me with this query please.

We want to create a generic alert message that can be changed.

For example.

Create a tick box called Alert message

Create a text field to show when the alert message has been ticked on a certain user.

Enter the message for example. Blackberry pilot

When a Service Desk Analyst logs a call and selects the user. It will display a message Blackberry Pilot.

If the same tick box and a different message is applied on another user in the user table. Say the message is Laptop pilot it will show that message.

Does anyone know if this will work or done something similar? for example if someone is part of two pilots how can the message be applied?

Kind Regards

Sarah

1 ACCEPTED SOLUTION

Hi Sarah,



I'll assume you have a field on your table called u_active which is a true/false field. You can add that to your script include query (before the msg.query() statement) something like this:



msg.addQuery('u_active', true);



If my assumptions are incorrect, adapt the statement or let me know the field name, type, value, etc. and I can advise.



Thanks.


View solution in original post

25 REPLIES 25

I'm working on this. There are several things I noted in the client script (like GlideAjax is misspelled) and the script include is incomplete. I'll have a script to test shortly.


Thanks so much Chuck.



Look forward to hearing from you.


Note this is untested code and likely needs some fields renamed to match your data model.



Client script (changed to onChange per your original requirements.) This needs to be created on each form you have a reference to sys_user where you want to pop the alert - e.g. incident.caller_id. Likely not incident.assigned_to.



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



  if (newValue === '' || isLoading) {


      return;


  }


  var user = g_form.getValue('sys_user');


  var ga = new GlideAjax('MessageMapper');


  ga.addParm('sysparm_name', 'getUser');


  ga.addParm('sysparm_user', newValue);


  ga.getXMLAnswer (alertMessageback);



  function alertMessageback(answer){


  if (answer)


  alert(answer);


      }


}



Script Include - again, check field names.



var MessageMapper = Class.create();


MessageMapper.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  getUser : function() {


  var userID = this.getParameter('sysparm_user');


  var msg = new GlideRecord('u_user_alert');


  msg.addQuery('u_user', userID);


  msg.query();



  var answer = [];


  while (msg.next()) {


  answer.push(msg.getValue('u_alert_string'));


  }



  return answer.join('\n');


  },



      type: 'MessageMapper'


});


Thanks for the help Chuck, much appreciated.



I have amended the client script



It's using the incident table


Field name customer which id field name caller_id (added in bld for the script so you can see where I put it and if it is right?




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


if (isLoading || newValue === '') {


return;


}



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



if (newValue === '' || isLoading) {


return;


}


var user = g_form.getValue('caller_id');


var ga = new GlideAjax('MessageMapper');


ga.addParm('sysparm_name', 'getUser');


ga.addParm('sysparm_user', newValue);


ga.getXMLAnswer (alertMessageback);



function alertMessageback(answer){


if (answer)


alert(answer);


}


}




Added your code and saved a Script include.




var MessageMapper = Class.create();


MessageMapper.prototype = Object.extendsObject(AbstractAjaxProcessor,



return answer.join('\n');


},



type: 'MessageMapper'


});



When I go to create a new incident


Select a user


I'm not getting a pop up.





As you said this could be field names or table name?


Time to check the browser's console log for client script issues and the server log for potential script include issues. Debugging these things is not a lot of fun - that's the downside of AJAX calls.



Additional alert messages in the client script may help, and gs.log() statements in the script include can shed some light.