- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 03:07 AM
Hi all,
I'm getting a JavaScript error in the Service Portal. Specifically when a catalogue client script runs.
Essentially the user selects a user from the sys_user reference field on the left which triggers a client script that utilizes a script include to return the users partner/practice code. Selecting a user on the left triggers the error message.
The error in the browser window is as below.
So I have already looked online and it seems apparent that a GlideAjax in the client script is not returning a value(?). See below the client script;
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading){
return;
}
if (newValue == '') {
g_form.setValue('u_partner_practice_code_s', '');
}
if (oldValue == newValue){
return;
}
var id = '';
id = newValue;
//alert('sys_id of user : ' + id);
var ga1 = new GlideAjax('SJPUserGroupUtils');
ga1.addParam('sysparm_name','GetUser');
ga1.addParam('sysparm_userId',id);
ga1.getXML(myCallbackFunction);
}
function myCallbackFunction(response){
var user_answer = response.responseXML.documentElement.getAttribute("answer");
if (user_answer){
// alert(user.user_name);
var user ='';
try{
user = user_answer.evalJSON(true); //runs for non service portal
}
catch(e){
user = JSON.parse(user_answer); // runs for service portal
}
g_form.setValue('u_partner_practice_code_s',user.u_partnership_number);
//alert (user.company);
var ga2 = new GlideAjax('SJPUserGroupUtils');
ga2.addParam('sysparm_name','GetCompany');
ga2.addParam('sysparm_company',user.company);
ga2.getXML(myCallbackCompanyFunction);
//g_form.setValue('PracticeName', );
}
}
function myCallbackCompanyFunction(response){
var comp_answer = response.responseXML.documentElement.getAttribute("answer");
if (comp_answer) {
var company = '';
try{
company = comp_answer.evalJSON(true); //runs for non service portal
}
catch(e){
company = JSON.parse(comp_answer); // runs for service portal
}
g_form.setValue('u_partner_practice_code_s',user.u_partnership_number);
}
}
I didn't write the above script so I'm a little unsure with what's going on but I'm sure the two GlideAjax's used both have a returned value.. myCallackFunction and myCallbackCompanyFunction.
Any ideas what might be missing from here? If adding the Script Include would help please let me know and I'll add it.
Thank you in advance.
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 03:11 AM
Apologies I've already solved this.
As I was writing out the question it made sense to me that the second part of the script, from g_form.setValue('u_partner_practice_code_s',user.u_partnership_number); onwards is not required or used.
I commented everything out past this point and didn't see the error message afterwards.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading){
return;
}
if (newValue == '') {
g_form.setValue('u_partner_practice_code_s', '');
}
if (oldValue == newValue){
return;
}
var id = '';
id = newValue;
//alert('sys_id of user : ' + id);
var ga1 = new GlideAjax('SJPUserGroupUtils');
ga1.addParam('sysparm_name','GetUser');
ga1.addParam('sysparm_userId',id);
ga1.getXML(myCallbackFunction);
}
function myCallbackFunction(response){
var user_answer = response.responseXML.documentElement.getAttribute("answer");
if (user_answer){
// alert(user.user_name);
var user ='';
try{
user = user_answer.evalJSON(true); //runs for non service portal
}
catch(e){
user = JSON.parse(user_answer); // runs for service portal
}
g_form.setValue('u_partner_practice_code_s',user.u_partnership_number);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 03:11 AM
Apologies I've already solved this.
As I was writing out the question it made sense to me that the second part of the script, from g_form.setValue('u_partner_practice_code_s',user.u_partnership_number); onwards is not required or used.
I commented everything out past this point and didn't see the error message afterwards.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading){
return;
}
if (newValue == '') {
g_form.setValue('u_partner_practice_code_s', '');
}
if (oldValue == newValue){
return;
}
var id = '';
id = newValue;
//alert('sys_id of user : ' + id);
var ga1 = new GlideAjax('SJPUserGroupUtils');
ga1.addParam('sysparm_name','GetUser');
ga1.addParam('sysparm_userId',id);
ga1.getXML(myCallbackFunction);
}
function myCallbackFunction(response){
var user_answer = response.responseXML.documentElement.getAttribute("answer");
if (user_answer){
// alert(user.user_name);
var user ='';
try{
user = user_answer.evalJSON(true); //runs for non service portal
}
catch(e){
user = JSON.parse(user_answer); // runs for service portal
}
g_form.setValue('u_partner_practice_code_s',user.u_partnership_number);
}
}