The CreatorCon Call for Content is officially open! Get started here.

Dependent variable: Variable is dependent on number of users in list collector variable

ChristineH85739
Tera Contributor

Hello,

I have a list collector variable and an attachment variable. The attachment variable should only be visible and mandatory if the number of users in the list collector is more than 5. 

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Use an onChange Catalog Client Script similar to this:

function onChange(control, oldValue, newValue, isLoading) {
    var usrArr = newValue.split(',');
    if (usrArr.length > 4) {
        g_form.setDisplay('v_attachment', true); //attachment variable name
    } else {
        g_form.setDisplay('v_attachment', false);

This should also cover hiding the variable when the form loads, but if not create a similar onLoad Catalog Client Script, replacing newValue with g_form.getValue('user_list').split(',') where 'user_list' is the name of your list collector variable.

Ankur Bawiskar
Tera Patron
Tera Patron

@ChristineH85739 

please follow script shared by @Brad Bowman  and that should solve your requirement.

💡 If my response helped, please mark it as correct ✔️ and close the thread 🔒 — this helps future readers find the solution faster! 🙏

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