Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more 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 ACCEPTED SOLUTIONS

Brad Bowman
Mega 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.

View solution in original post

Ankur Bawiskar
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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Brad Bowman
Mega 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

@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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

ChristineH85739
Tera Contributor

Thank you both