
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 06:38 AM
Good Morning,
I have been attempting to piece together a client script that helps me pull data from one table and display it as an alert on the incident form. The business reason behind this is that our managers need to alert the technicians about problems in locations without relying on the technician to go look at a note somewhere in the company’s information.
First a little reference as to the structure of our instance:
The Incident Form
The company profile for Willacy County, TX with an custom alert made by a manager.
This alert is stored in our u_customer_alerts table.
I am open to any alternative suggestions but what I would like to do is when the Company/Facility field changes on the incident form I would like the script to search the u_customer_alerts table for a matching name (in this case Willacy County, TX) then find an alert where the alert category is Incident Alert and finally get the note on the alert and return it to the incident form via an alert(u_note); method so it pops up for the technician.
Here is the client script I have to do this so far but it’s just not returning any results.
Type: ON CHANGE
Field Name: Company / Client
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
{
return;
}
//The only way I could figure out how to search was to use this line plus the function
var comp = g_form.getReference('company', getCompany);
function getCompany(comp)
{
//Look at the customer alerts
var findAlerts = new GlideRecord('u_customer_alerts');
//Limit by where the name is the same as the one in the company field
findAlerts.addQuery('u_client_profile', comp.name);
//Limit by ones with type Incident Alert
findAlerts.addQuery('u_alert_category', 'Incident Alert');
//Run it
findAlerts.query();
//Return the alert
alert('ALERT: ' + findAlerts.getDisplayValue(u_notes));
}
So there we have it, I am at a loss because nothing comes back…any ideas how I can fix this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 07:51 AM
Did you get a chance to check the response here. Putting the response here again with little modification. Please check if this helps.
Client Script:
var gAjax = new GlideAjax("getAlert");
gAjax.addParam("sysparm_name", "findAlerts");
gAjax.addParam("sysparm_company", g_form.getDisplayBox('company').value);
gAjax.addParam("sysparm_category", 'Incident Alert');
gAjax.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
alert('ALERT: ' + answer);
}
Client callable Script Include:
var getAlert = Class.create();
getAlert.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findAlerts : function() {
var gr = new GlideRecord('u_customer_alerts');
gr.addQuery('u_client_profile', this.getParameter('sysparm_company'));
gr.addQuery('u_alert_category', this.getParameter('sysparm_category'));
gr.query();
if(gr.next())
return gr.u_notes;
},
type: 'getAlert'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 10:44 AM
When I change it to
var target = new GlideRecord('u_customer_alerts');
target.addQuery('u_client_profile', g_form.getValue('company'));
target.query();
while (target.next())
{
alert(target.u_notes);
}
No results are returned but they should because if I type
var value = g_form.getValue('company');
alert(value);
at the top it returns a sys_id on the alert before moving into the query.
EDIT: I also tried substituting in the value variable from the top into the query because I know it gives a sys_id but still nothing.
EDIT 2: I think I am on to something which makes some of the first replies make a lot more sense. The sys_id I am getting back is not the one for that record on the u_customer_alerts table because the client profile field I am trying to read is a reference field and it points to my core_company table.
It fails because there's no notes in that table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 08:10 PM
Can you try this.
var comp = g_form.getReference('company', getCompany);
function getCompany(comp) {
var findAlerts = new GlideRecord('u_customer_alerts');
findAlerts.addQuery('u_client_profile', comp); // just remove .name from both
findAlerts.query(); //Look at the u_notes field on the record and show it in an alert
while(findAlerts.next()){
alert('ALERT: ' + findAlerts.u_notes.toString());
}
}
Thanks