
- 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 08:47 PM
This man is amazing!!! He went above and beyond and I would have NEVER gotten this right without him. I wish I could mark as correct 100x over!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 09:55 AM
I'd like to backup just a bit because after trying and failing so many times I went back to one of my first scripts:
ON CHANGE
Field: Company
Script
var target = new GlideRecord('u_customer_alerts');
target.query();
while (target.next())
{
alert(target.u_notes);
}
This script works but it returns the notes for each record in that table.
All I need is for it to only return the record where the name of the company field on the incident record matches the u_client_profile field on the u_customer_alerts table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 09:58 AM
Hi,
See below script:
var target = new GlideRecord('u_customer_alerts');
target.addQuery('u_client_profile',current.company);//Expecting that this Profile field hold company data for that alert and company is a current company on the form.
target.query();
while (target.next())
{
alert(target.u_notes);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 10:06 AM
Can't use current in a client script but I can get this to return a single note. The problem is that I have to pass a SYS ID and not the name
var target = new GlideRecord('u_customer_alerts');
target.addQuery('u_client_profile', '088cf3eedb8857406a29561bdc96192f');
target.query();
while (target.next())
{
alert(target.u_notes);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 10:36 AM
Hi,
You can use g_form.getValue('field_name');
Thanks,
Ashutosh Munot