- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:09 PM - edited 07-07-2024 12:11 PM
Hi Team,
Am trying with below client script and server side script to get the alert message on form for the selected caller.
Client script
Script include
But am not getting null, can someone help me out to find the error
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:36 PM
Hi @Roshini ,
All code is correct, just a mistype is there which is causing the issue.
In Catalog Client Script, Instead of:
alertDetails.addParam('sysparam_name','userDetails');
alertDetails.addParam('sysparam_userid', newValue);
It will be:
alertDetails.addParam('sysparm_name','userDetails');
alertDetails.addParam('sysparm_userid', newValue);
In the Script include, Instead of:
var id = this.getParameter('sysparam_userid');
It will be:
var id = this.getParameter('sysparm_userid');
The rectified final code will be:
Script Include:
var UserLearning = Class.create();
UserLearning.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userDetails: function() {
var id = this.getParameter('sysparm_userid');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
var userObj = {
"email": gr.getValue("email"),
};
return JSON.stringify(userObj);
}
},
type: 'UserLearning'
});
Catalog Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var alertDetails = new GlideAjax('UserLearning');
alertDetails.addParam('sysparm_name', 'userDetails');
alertDetails.addParam('sysparm_userid', newValue);
alertDetails.getXMLAnswer(details);
function details(detail) {
if (detail) {
var a = JSON.parse(detail);
alert("email is " + a.email);
}
}
}
The output is:
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:15 PM
Hi @Roshini
Tyr this:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var alertDetails = new GlideAjax('UserLearning'); // Corrected script include name
alertDetails.addParam('sysparam_name', 'userDetails');
alertDetails.addParam('sysparam_userid', newValue);
alertDetails.getXMLAnswer(function(response) {
var detail = response.responseText;
if (detail) {
var a = JSON.parse(detail);
alert("Email is " + a.email);
} else {
alert("No email found for the selected user.");
}
});
}
Script Include
var UserLearning = Class.create();
UserLearning.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userDetails: function() {
var id = this.getParameter('sysparam_userid');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
var userObj = {
"email": gr.getValue("email"),
};
return JSON.stringify(userObj);
} else {
return "{}"; // Return empty object if user is not found
}
},
type: 'UserLearning'
});
———————————————-
Please consider marking my reply as Helpful👍 and/or Accept Solution☑️, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:17 PM
Hi there @Roshini
Hi Roshini,
Your script looks correct, check these things to check and adjust:
Make sure the Script Include UserLearning is marked as Client Callable.
Add some debugging information to see where it might be failing.
Client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var alertDetails = new GlideAjax('UserLearning');
alertDetails.addParam('sysparam_name', 'userDetails');
alertDetails.addParam('sysparam_userid', newValue);
alertDetails.getXMLAnswer(details);
function details(response) {
if (response) {
var a = JSON.parse(response);
alert("email is " + a.email);
} else {
alert("No response from server");
}
}
}
SI
var UserLearning = Class.create();
UserLearning.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userDetails: function() {
var id = this.getParameter('sysparam_userid');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
var userObj = {
"email": gr.getValue("email")
};
return JSON.stringify(userObj);
} else {
return JSON.stringify({"error": "User not found"});
}
},
type: 'UserLearning'
});
make sure the Client Callable checkbox is checked.
Ensure newValue in your client script is the correct sys_id of the user.
If this helps kindly accept the answer thanks mych,
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:28 PM
Hi Thanks or your reply,
am getting no response from server while modifying the script.
is there any alteration can be done to get the value.
The user is havin email id in sys_user profile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2024 12:36 PM
Hi @Roshini ,
All code is correct, just a mistype is there which is causing the issue.
In Catalog Client Script, Instead of:
alertDetails.addParam('sysparam_name','userDetails');
alertDetails.addParam('sysparam_userid', newValue);
It will be:
alertDetails.addParam('sysparm_name','userDetails');
alertDetails.addParam('sysparm_userid', newValue);
In the Script include, Instead of:
var id = this.getParameter('sysparam_userid');
It will be:
var id = this.getParameter('sysparm_userid');
The rectified final code will be:
Script Include:
var UserLearning = Class.create();
UserLearning.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userDetails: function() {
var id = this.getParameter('sysparm_userid');
var gr = new GlideRecord('sys_user');
if (gr.get(id)) {
var userObj = {
"email": gr.getValue("email"),
};
return JSON.stringify(userObj);
}
},
type: 'UserLearning'
});
Catalog Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var alertDetails = new GlideAjax('UserLearning');
alertDetails.addParam('sysparm_name', 'userDetails');
alertDetails.addParam('sysparm_userid', newValue);
alertDetails.getXMLAnswer(details);
function details(detail) {
if (detail) {
var a = JSON.parse(detail);
alert("email is " + a.email);
}
}
}
The output is:
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.