- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:30 PM
I'm creating a catalog item wherein I need to auto populate the computer name field and the type of my computer name field is lookup field. I'm having a hard time with the catalog client script and script include. Can someone help me with this since I tried to research but it's not working in my side.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:39 PM
Hi,
you can modify the code as per your requirement and please let me know whether it is useful or not.
script include
var PopulateWorkstationName = Class.create();
PopulateWorkstationName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComputer: function() {
var computer = '';
var uid = this.getParameter('sysparm_usid');
var com = new GlideRecord('cmdb_ci_computer');
com.addQuery('assigned_to', uid);
com.query();
if (com.next()) {
computer = com.sys_id;
}
return computer;
},
type: 'PopulateWorkstationName'
});
On-load Client script
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_form.getValue('caller_id');
var ga = new GlideAjax('PopulateWorkstationName');
ga.addParam("sysparm_name", "getComputer");
ga.addParam("sysparm_usid", user);
ga.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_user_computer', answer); //you can mention your field name.
}
Thanks
SP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:39 PM
Hi,
you can modify the code as per your requirement and please let me know whether it is useful or not.
script include
var PopulateWorkstationName = Class.create();
PopulateWorkstationName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComputer: function() {
var computer = '';
var uid = this.getParameter('sysparm_usid');
var com = new GlideRecord('cmdb_ci_computer');
com.addQuery('assigned_to', uid);
com.query();
if (com.next()) {
computer = com.sys_id;
}
return computer;
},
type: 'PopulateWorkstationName'
});
On-load Client script
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_form.getValue('caller_id');
var ga = new GlideAjax('PopulateWorkstationName');
ga.addParam("sysparm_name", "getComputer");
ga.addParam("sysparm_usid", user);
ga.getXML(getResponse);
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_user_computer', answer); //you can mention your field name.
}
Thanks
SP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 08:03 PM
I have provided above code. please verify it and let me know @sailor_moon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 08:15 PM
Hi @SP22 I tried to modify your code but when I change my g_form.setValue(computer_name, answer)
This is what I got
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 08:32 PM
Hi @sailor_moon ,
can you please send me the full screenshot.
you need to go to type specification add reference table as cmdb_ci_computer (refer screenshot of @Murthy Ch )