Catalog item_catalog client script is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 06:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 08:58 PM
Hi Ankur
My version it Tokyo, however auto population field is not visible in my instance
we can achieve these with script include and ajax & auto populated filed which was available in Utah version.. but my question is i want to achieve through catalog client script only, is it possible or not
Regards
Khasim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:18 PM
yes it's possible
please share the script here and not the screenshots of the script
what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 09:35 PM
Hi Ankur
pls check the below code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 02:58 AM
Hi Ankur
pls help in these case
Regards
Khasim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 07:46 PM - edited 11-06-2023 10:29 PM
Hi @shaikkhasim ,
Note: Use proper backend name of ur variables wherever required.
Here is the solution to this -
Create a new client callable script include with following function
var UserDetails = Class.create();
UserDetails.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUserInfo: function() {
var details = {};
var userId = this.getParameter('sysparm_user_id');
var userObj = new GlideRecord('sys_user');
userObj.addQuery('sys_id', userId);
userObj.query();
if (userObj.next()) {
details.email= userObj.email_id.toString();
}
return JSON.stringify(details);
},
type: 'UserDetails'
});
Create a new catalog client script on the record producer/request form
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('UserDetails');
ajax.addParam('sysparm_name', 'getUserInfo');
ajax.addParam('sysparm_user_id', g_form.getValue('employee_name')); // change variable name here
ajax.getXML(doSomething);
function doSomething(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answers = JSON.parse(answer);
g_form.setValue('var_email_id', answers.email.toString()); // change variable name here
}
}
Thanks,
Danish