- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 04:10 AM
Hello Team,
I have Requirement :-
consider a scenario where several of your catalog items may require the same functionality (e.g.
populating specific user data automatically like Mobile number and location when an user is selected). Rather than scripting this functionality for each catalog item in a Catalog Client Script you could do it once in a Script Include
which you could call from your Catalog Client Script for each Catalog Item. Please explain here with example.
Note:- we need this solution without using Catalog Data lookup Definition .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 05:14 AM - edited 12-21-2022 05:15 AM
Hi Neelash,
Please find the below example where I auto-populated user-related fields.
Here I am populating Email ID based on the User selected :
OnChange Client Script on User field :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abc = new GlideAjax("Script Include Name");
abc.addParam("sysparm_name", 'Function Name');
abc.addParam("sysparm_userID", newValue); //sysparm_userID is the declared variable in Scriptinclude.
abc.getXML(Hello);
function Hello(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("email", answer);
}
}
Client-Callable Script Include :
var AutopopulateEMailID = Class.create();
AutopopulateEMailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myfunction: function(){
var usr = this.getParameter('sysparm_userID'); //sysparm_userID is the parameter used in Client script
var tab = new GlideRecord("sys_user");
tab.addQuery("sys_id",usr);
tab.query();
if(tab.next()){
var mail = tab.getValue('email');
}
return mail;
},
type: 'AutopopulateEMailID'
});
You can use the same script include in multiple catalog items.
Please feel free to ask incase of any queries.
Please mark this as correct if it resolved your query.
Regards,
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 04:13 AM
So before giving you a solution, I would like to know your initial thoughts around how you want to tackle this? Have you found anything else on the community that might help your requirement, and how does you current script include look like? Have you tried making a GlideAjax call before? 🙂
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 04:59 AM
As i am new to the ServiceNow I call script include to the Business rule and Client-side Script Creating New Object. Also, I had gone through some Glide Ajax concept where watched some videos and tried on client script. However, it comes to service Catalog I am not sure above requirement how we can achieve this. I just want to know how we can achieve this on Catalog Item.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 05:14 AM - edited 12-21-2022 05:15 AM
Hi Neelash,
Please find the below example where I auto-populated user-related fields.
Here I am populating Email ID based on the User selected :
OnChange Client Script on User field :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abc = new GlideAjax("Script Include Name");
abc.addParam("sysparm_name", 'Function Name');
abc.addParam("sysparm_userID", newValue); //sysparm_userID is the declared variable in Scriptinclude.
abc.getXML(Hello);
function Hello(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("email", answer);
}
}
Client-Callable Script Include :
var AutopopulateEMailID = Class.create();
AutopopulateEMailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myfunction: function(){
var usr = this.getParameter('sysparm_userID'); //sysparm_userID is the parameter used in Client script
var tab = new GlideRecord("sys_user");
tab.addQuery("sys_id",usr);
tab.query();
if(tab.next()){
var mail = tab.getValue('email');
}
return mail;
},
type: 'AutopopulateEMailID'
});
You can use the same script include in multiple catalog items.
Please feel free to ask incase of any queries.
Please mark this as correct if it resolved your query.
Regards,
Deepika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 10:33 PM
Hello Deepika,
This is for only one field that you provided the logic, this is only for email populate if want, populate multiple filed like mobile number and other like location. so, in return we cannot Paas all those parameters. please explain how we can use Json in this .