- 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 08:01 PM
Hi @sailor_moon
Tell me one thing what if requested for user has more than 1 asset?
Which asset you want to get populated?
So that I can give you the complete script.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2022 07:38 PM
Hi @Murthy Ch
Hope all well!
In this , I have a requirement , I need to show the list of assigned computer (All, if more than one) and then I can pick one of them in order to raise the request . And also that should be on change. Can you help in this ?