- 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 05:20 AM
I would suggest to take a look at the following Article from Tim: https://snprotips.com/efficientgliderecord
You might as well learn some cool and efficient ways to this going forward! 🙂
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 05:29 AM
Thank you so much 🙂