How to show devices given to user through one catalog item in another catalog item

Servicenow use1
Tera Contributor

Hi , 

we have a catalog item (first RITM) that collects the info of devices (laptops and peripherals) for the new user. When the user is not joining, then there is a new catalog item (second RITM) which needs to collect all the devices provided in the previous request. How to show all the devices tagged to the person from first RITM in the second RITM

 

 

 

 

1 ACCEPTED SOLUTION

Hi,

I believe "devices_to_be_returned" is referring to model table

update as this

var getMyDevices = Class.create();
getMyDevices.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDevices: function() {
        var user = this.getParameter('sysparm_user');
        var arr = [];
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("cat_item.name", "RITM 1"); // name of your catalog item
        gr.query();
        while (gr.next()) {
            if (gr.variables.requested_on_behalf_of == user)
                arr.push(gr.variables.model.sys_id.toString());
        }
        return arr.toString();

    },


    type: 'getMyDevices'
});

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Hi,

you can query all RITMs and get the variable value for Model and push the record sysId and then return that and set the value

logic still remains the same just the approach will change based on your requirement

If my response helped please mark it correct and close the thread so that it benefits future readers.

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I made changes by copying the solution in above post but it is not showing all the devices tagged to this person (through RITM-1). The following is being shown.

For the devices to be returned, it should be a list collector field populated with all the devices he got from RITM-1.

find_real_file.png

Catalog client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }



   if (newValue == '')
        g_form.clearValue('devices_to_be_returned');

   if (oldValue != newValue) {
        var ga = new GlideAjax('getMyDevices');
        ga.addParam('sysparm_name', "getDevices");
        ga.addParam('sysparm_user', newValue);
        ga.getXMLAnswer(function(answer) {
            if (answer != '') {
                g_form.setValue('devices_to_be_returned', answer);
            }
        });
        
    }
}

 

script include:

var getMyDevices = Class.create();
getMyDevices.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   getDevices: function() {
       var user = this.getParameter('sysparm_user');
        var arr = [];
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("cat_item.name", "RITM 1"); // name of your catalog item
        gr.query();
        while (gr.next()) {
            if (gr.variables.requested_on_behalf_of == user)
               arr.push(gr.variables.model.sys_id);
        }
       return 'sys_idIN' + arr.toString();

   },


   type: 'getMyDevices'
});

Please let me know the changes required

Hi,

I believe "devices_to_be_returned" is referring to model table

update as this

var getMyDevices = Class.create();
getMyDevices.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDevices: function() {
        var user = this.getParameter('sysparm_user');
        var arr = [];
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("cat_item.name", "RITM 1"); // name of your catalog item
        gr.query();
        while (gr.next()) {
            if (gr.variables.requested_on_behalf_of == user)
                arr.push(gr.variables.model.sys_id.toString());
        }
        return arr.toString();

    },


    type: 'getMyDevices'
});

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader