- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 10:17 AM
Hello,
I created 2 tables in app engine servicenow, table "Requests" and table "Requestor Details"
Now my table "Requests" has Field "Name" that is reference to my table "Requestor Details", what i want and need is that if i change the name in the "Requests" the "Email" Field will be automatically populated from the value in "Requestor Details"
My code so far
Script Includes
---------I tried to run in Script - Background, and i am getting correct results.
Thank you!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 08:23 PM
Hi @glennjasper0 ,
you have not followed glide ajax syntax.
change below.
check this blog for Glide Ajax : https://servicenowwithrunjay.com/glideajax-in-servicenow/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 08:23 PM
Hi @glennjasper0 ,
you have not followed glide ajax syntax.
change below.
check this blog for Glide Ajax : https://servicenowwithrunjay.com/glideajax-in-servicenow/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2024 04:56 AM
Hi, try the below code
CLIENT SCRIPT::
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2024 08:30 AM
Hello @glennjasper0
There are few points to take care:
- Script include should be Client callable.
- Once a script include is created without checkbox the client callable field, changing this later will not make it client callable. A new script include has to be created in that case.
- From the script it is noticed that script include is not client callable.
- This is how the script looks like if it is client callable
- An onChange client script to request table with field set to name is created.
- client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setValue('email', '');
return;
}
// GlideAjax call to the Script Include
var ga = new GlideAjax('Populate_email_on_name_change');
ga.addParam('sysparm_name', 'getEmail');
ga.addParam('sysparm_requesterId', newValue); //returns sys_id of reference field 'name'
ga.getXMLAnswer(function(response) {
console.log('Response from server:', response);
if (response) {
g_form.setValue('email', response);
} else {
g_form.setValue('email', '');
}
});
}
- script include:
var Populate_email_on_name_change = Class.create();
Populate_email_on_name_change.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmail: function() {
var email = '';
var sysId = this.getParameter('sysparm_requesterId');
var gr = new GlideRecord('x_1566811_notifi_0_requestor_details');
gr.addQuery('sys_id', sysId);
gr.query();
if (gr.next()) {
email = gr.getValue('email');
gs.info('Email found for Name "' + name + '": ' + email);
} else {
gs.info('No record found for Name: ' + name);
}
return email;
},
type: 'Populate_email_on_name_change'
});​
- Note: Please create a fresh script include with client callable enable. Accordingly call it from client script.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2024 05:25 PM
Hello @Juhi Poddar ,
It gives me this message,
This is my code and setting looks like in script include, i don't have option "Client callable" like yours