Error Message Assistance: onChange script error: TypeError: GlideRecord is not a constructor function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2021 06:07 AM
I am currently working on a ServiceNow Application for our COVID testing site that will allow them to create a database for the testing registrations. (We're not storing results, the purpose of this is to make reporting easier and to have a registration database that can be used to easily identify a test to a person in case Upstate only returns the barcode with the results). I work for a Higher Ed insinuate and the Spring Semester starts next week so we're looking to have this ready for deployment before our students come back.
We currently have the system setup for a contact-less registration. We have a Proxy Card reader that they can use so that person getting tested can scan their Proxy Cards and the system will pull their information and will automatically populate the form for the worker. I have a client script that works on the self-service side that when the field changes will query the sys_user table for the ID number and will return the name, but when I use that in the 'itil' form I get the following error:
1. I was hoping to get some advice on how to best approach this. I'm working on brushing up my AJAX and have gone thru some of the previous responses that are similar to this, but this is new territory for me.
2. My organization has a few client scripts in our Incident and Request Management forms that use the GlideRecord to query various tables in order to populate fields on our forms. Will we need to go thru those scripts and convert them to use the Glide Ajax method?
I hope this makes sense and I appreciate any assistance or pointers that anyone can offer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2021 06:20 AM
2 - no
1 - set your GlideAjax SI to client callable. Do not use GlideRecord in client scripts as it will fail. Can you post the AJAX + Client Script where you cann it, so we can check it out together?
P.S. GlideRecord in UI Action - thats fine but in Client Script - are you sure?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2021 07:48 AM
Hi Joro, thanks for the response!
Below is what I have so far. The issue I am having right now is that I can't seem to get into the getUserInfo function in the Script Include to call properly. It doesn't appear to be triggering and I keep getting a null returned. (In the script include I also tried testing by having it just return a test value with nothing else).
Client Script:
//Code below tries to use AJAX
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
{
return;
}
//Create new AJAX Call
var ga = new GlideAjax('covid_lookup_user_proxid');
var prox = g_form.getValue('u_proxid');
//ga.addParam('', ''); Shell code for adding parameters to the AJAX call
//ga.addParam('', g_form.getValue('')); Shell code for adding a field variable to the
alert('Setting sys_proxid to: '+ prox);
ga.addParam('sysparm_name', 'getUserInfo'); //Function name
ga.addParam('sys_proxid', prox);
alert('before XML:');
ga.getXML(getUserInfoAJAX); // Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)
alert('after XML');
}
// Callback function to process the response returned from the server
function getUserInfoAJAX(response)
{
alert('response:' + response);
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('name', answer);
}
Script Include:
var covid_lookup_user_proxid = Class.create();
covid_lookup_user_proxid.prototype = Object.extendsObject(global.AbstractAjaxProcessor,
{
getUserInfo:function()
{
var retVal = ''; //Return value
alert('inside script include');
//var = this.getParameter(''); //shell for retrieving the parameter from the client script
var proxid_number = this.getParameter('sys_proxid'); //Retrieve ProxID number
var user = new GlideRecord('sys_user');
user.addQuery('u_proxid', proxid_number);
var found_user = "No";
user.query();
/*if(user.next())
{
//g_form.setValue('name',user.sys_id);
found_user = "Yes";
retVal = user.sys_id;
//g_form.setValue('first_name', count);
//g_form.setValue('a_number', '');
}*/
retVal = 'test';
return retVal;
},
type:'covid_lookup_user_proxid',
isPublic: true
});
Here are the settings on the Script Include as well:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2021 08:16 AM
update below line.
var ga = new GlideAjax('covid_lookup_user_proxid');
You should use scope name
eg:
var ga = new GlideAjax('<your scope name>.covid_lookup_user_proxid');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2021 08:19 AM
Also,, please remove alert() from script include, to check the log result use gs.info()
alert works at client side.
