OnChange of checkbox field Auto add users to list collector variable

SanaPR
Giga Guru

Hi Everyone.. Iam stuck with an OnChange client script that goes nowhere . The requirement is

There is a checkbox variable on a catalog form called Access

when it is checked true, I am trying to add two specific users in a list collector variable called Managers

 

They are static values and hence Im using sys IDs of both users in the client script.

Can someone please help me with code snippet that will work both in service catalog and servuce portal. I tried with addOptions removeOptions and that doesn’t seem to be working on portal returns Javascript error.

1 ACCEPTED SOLUTION

Hi @SanaPR ,

 

Try the below in onChange client Script:

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

    if (newValue == 'true') {
        var usersList = '4ae3ab0753101200ed11da86a11c0881,3f0370019f22120047a2d126c42e705e';
            g_form.setValue('managers', usersList.toString());
    }
}

 

Result:

SN_Learn_0-1722243394112.png

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

4 REPLIES 4

SN_Learn
Kilo Patron
Kilo Patron

Hi @SanaPR ,

 

Please check the below article, it will fulfill your requirement:

Dynamically set list collector on change of variable 

Setting List collector values in Service Portal by catalog client script 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

SanaPR
Giga Guru

Hi , I referred the above article. This has a script include for dynamic list collector variables. For me I have static users that can be mentioned in the client script with sys IDs. Is there a way to achieve this without using script include?

thank you for your help!

Hi @SanaPR ,

 

Try the below in onChange client Script:

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

    if (newValue == 'true') {
        var usersList = '4ae3ab0753101200ed11da86a11c0881,3f0370019f22120047a2d126c42e705e';
            g_form.setValue('managers', usersList.toString());
    }
}

 

Result:

SN_Learn_0-1722243394112.png

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

SanaPR
Giga Guru

This worked except userList var needed to be an array. Here’s the exact ode that worked for me.

 

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

//Type appropriate comment here, and begin script below
if (newValue == 'true') {
var userList = ['77a8969c87e3515068ac2f88dabb35cb','29da121c87ef1110d359bae6dabb3583'];
g_form.setValue('managers’, userList.join(','));

}
else {
g_form.clearValue('managers’);
}
}


Thank you for all the help!