- 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:40 PM
Hi @sailor_moon
Which value you need to populate in the computer name field?
If it is some specific value to be auto populated you can set the value in default value field:
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:43 PM - edited ‎11-14-2022 07:44 PM
I need to auto populate this field based on the requested_for user that is selected, and the value that needs to come out is the asset tag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:54 PM
Hi @sailor_moon
Then you can try like below there is no client script required.
I hope you have configured variable something like below:
If yes you can use below logic in default value field:
javascript: var dt; var gr=new GlideRecord("cmdb_ci_computer"); gr.addQuery("assigned_to",gs.getUserID()); gr.query(); if(gr.next()) { dt=gr.asset_tag} dt;
//in place of gs.getUserID() just replace with current.variables.requestedFor_VariableName;
Hope it helps:)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:56 PM
Hi @sailor_moon
If you want to happen this during onload of the form you can use above suggestion but if we want to on change of requested for then you have write client script and script include as well.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:58 PM
Yup I need it onchange