Catalog item - auto populate a MRVS with users assigned assets

Bidduam
Tera Guru

I'd like to have a catalog item that displays the currently assigned assets for a user in a multi row variable set.

 

I feel this is the best way to display all assets on a catalog item since different users will have differing numbers of assets assigned to them.

Anyone know how I'd go about this?

Bidduam_0-1737439716855.png

 

1 ACCEPTED SOLUTION

@Bidduam 

Here you go without Script Include

1) create catalog client script which applies on Catalog Item

2) UI Type- ALL

3) Script as this

function onLoad() {

    var gr = new GlideRecord("alm_asset");
    gr.addQuery("assigned_to", g_user.userID);
    gr.query(checkRecord);
    function checkRecord(gr) {
        var arr = [];
        while (gr.next()) {
            var obj = {};
            obj['mrvs_asset_number'] = gr.sys_id.toString();
            obj['mrvs_asset_description'] = gr.display_name.toString(); // stores the asset display name

            // if you wish to populate the model name then you will have to use split on the display name and store
            arr.push(obj);
        }
        g_form.setValue('mrvs_assigned_assets', JSON.stringify(arr));
    }
}

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

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

View solution in original post

11 REPLIES 11

Community Alums
Not applicable

Thank you, that is not quite what I'm looking for. That is populating details based on a selection, I want to auto populate assets on load of the catalog item for assets assigned to the current user. There should be nothing the user needs to select in order to populate if possible?

@Bidduam 

script shared in my below post should help you do that

Do let me know if any help required

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

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Bidduam 

so that MRVS should show asset information for assets belonging to logged in user or some other user which can be selected from some other variable?

you can set value in MRVS variable which is an array of json object

I shared solution for something similar in past, enhance for your requirement

How to auto populate project details in a multi row variable set 

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

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