Auto populate the computer name field

sailor_moon
Tera Contributor

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.

1 ACCEPTED SOLUTION

SP22
Mega Sage
Mega Sage

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.

View solution in original post

11 REPLIES 11

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.

 

Thanks,
Murthy

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 ?