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

OMG - You are a legend @Ankur Bawiskar , works beautifully 😁

 

Thank you very much

@Bidduam 

Glad to help.

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