Mutliple users select in requested for field choices

Manohararuna
Tera Contributor

Hello Everyone,

 

       I have one requirement. 

Requirement is In Catalog form having the Requestor For field (reference type--user table) and Application filed(reference type- App table) .If i select Minipay in Application then i am able to select multiple users in Requestor For field. This requirement only for Minipay option .suppose if i select another application then i am able to select single user at time in Requestor For field.

Please provide solution to this one.

 

Thanks,

Manohararuna

2 ACCEPTED SOLUTIONS

Rafael Batistot
Tera Sage

Hi @Manohararuna 

 

The Requested For variable in a catalog item is a reference type (to sys_user). Out-of-the-box, reference variables only allow one value. To allow multiple selections, you need to use a Lookup Select Box / Multi-row variable set / Glide List.

So the trick is:

  • You actually need two different variables:

    • requested_for_single → type = Reference (sys_user), for normal use.

    • requested_for_multi → type = Lookup Select Box (or Glide List), for Minipay.

  • Then use a Catalog Client Script (onChange of Application) to show/hide the right one.


Example Client Script

  • Type: Catalog Client Script

  • Applies to: Item

  • When: onChange → Application

 

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

    // If Application = Minipay
    if (g_form.getDisplayBox('application').value == 'Minipay') {
        g_form.setDisplay('requested_for_multi', true);
        g_form.setMandatory('requested_for_multi', true);

        g_form.setDisplay('requested_for_single', false);
        g_form.setMandatory('requested_for_single', false);
        g_form.clearValue('requested_for_single');
    } else {
        g_form.setDisplay('requested_for_single', true);
        g_form.setMandatory('requested_for_single', true);

        g_form.setDisplay('requested_for_multi', false);
        g_form.setMandatory('requested_for_multi', false);
        g_form.clearValue('requested_for_multi');
    }
}

View solution in original post

Shashank_Jain
Kilo Sage

@Manohararuna ,

 

  • Create Reference variable for single selection.

  • Create List Collector for multiple selection.

  • Control visibility via Client Script.

  • Only one will be shown at a time depending on Application selection.

 

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

View solution in original post

5 REPLIES 5

Rafael Batistot
Tera Sage

Hi @Manohararuna 

 

The Requested For variable in a catalog item is a reference type (to sys_user). Out-of-the-box, reference variables only allow one value. To allow multiple selections, you need to use a Lookup Select Box / Multi-row variable set / Glide List.

So the trick is:

  • You actually need two different variables:

    • requested_for_single → type = Reference (sys_user), for normal use.

    • requested_for_multi → type = Lookup Select Box (or Glide List), for Minipay.

  • Then use a Catalog Client Script (onChange of Application) to show/hide the right one.


Example Client Script

  • Type: Catalog Client Script

  • Applies to: Item

  • When: onChange → Application

 

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

    // If Application = Minipay
    if (g_form.getDisplayBox('application').value == 'Minipay') {
        g_form.setDisplay('requested_for_multi', true);
        g_form.setMandatory('requested_for_multi', true);

        g_form.setDisplay('requested_for_single', false);
        g_form.setMandatory('requested_for_single', false);
        g_form.clearValue('requested_for_single');
    } else {
        g_form.setDisplay('requested_for_single', true);
        g_form.setMandatory('requested_for_single', true);

        g_form.setDisplay('requested_for_multi', false);
        g_form.setMandatory('requested_for_multi', false);
        g_form.clearValue('requested_for_multi');
    }
}

RaghavSh
Kilo Patron

Reference field can only have one value, you will have to change "requested for" variable to list collector for your requirement. 

OR

Create new variable of list collector type, it can store multiple values. In case of "Minipay" multiple users can be selected and for others single user (this can be handled trough on change client script)


Raghav
MVP 2023

Ankur Bawiskar
Tera Patron
Tera Patron

@Manohararuna 

Requested For is Reference or List collector?

If reference then you can anyhow select only 1 user.

Your requirement is not clear.

Share some screenshots.

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

Hello Ankur, 

 

    In below images as of now Requested for is Reference filed and able to select one option for all application .But my requirement is only for one application on tis catalog item.

suppose if i select Minipay application in Application field then in Requestor field able to select multiple user .For other applications it should normal as like now.

Due to this able to order multiple catalog item at time for multiple users.

 

Manohararuna_0-1755750543192.pngManohararuna_1-1755750591226.png