Limit the additional assignee list to only 2 users

Shree Nag
Tera Expert

Hello,

Appreciate your help !
We have added Additional assignee list to incident form.
Now there is a requirement to limit the additional assignee to only 2 users.
One cannot add more than 2 users to the list.
Is that possible, If so could you please guide us on the steps to limit?

 

-Thanks

Shree

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Shree Nag ,

 

Try this 

function onSubmit() {

    var assignees = g_form.getValue('YourFieldName').split(',');

 

    if (assignees.length > 2) {

        g_form.showFieldMsg('YourFieldName', 'You cannot add more than 2 assignees.', 'error');

        return false;

    }

    return true;

}

 

If my answer helped you in any way, please mark it as helpful or correct. 

 

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi @Shree Nag ,

 

Try this 

function onSubmit() {

    var assignees = g_form.getValue('YourFieldName').split(',');

 

    if (assignees.length > 2) {

        g_form.showFieldMsg('YourFieldName', 'You cannot add more than 2 assignees.', 'error');

        return false;

    }

    return true;

}

 

If my answer helped you in any way, please mark it as helpful or correct. 

 

Amit Verma
Kilo Patron
Kilo Patron

Hi @Shree Nag 

 

Below posts could be helpful :

https://www.servicenow.com/community/csm-forum/how-to-limit-the-list-collector-choices-selection/m-p...

https://www.servicenow.com/community/developer-blog/servicenow-learning-139-how-to-restrict-values-t...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Ankur Bawiskar
Tera Patron
Tera Patron

@Shree Nag 

you can do this using 2 ways

1) onChange on that field and check the length and show error message on form or field

OR

2) before update/insert BR and show error message

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

Shree Nag
Tera Expert

Hello,

Thank you all for the response.

 

I added the client script. The error message pops out when I'm adding more than 2 assignees, but I can still add the additional assignee to the bucket and I can update with more than 2 assignees.

 

What Am 'I missing in this client script, that avoids even adding the additional assignee to the bucket

 

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

    var values = g_form.getValue('additional_assignee_list').toString().split(',');
    if (values.length > 2)
    {
    g_form.showFieldMsg('additional_assignee_list', 'You cannot add more than 2 assignees.', 'error');
       
        return false;
    }
    else
    {
        return true;
    }
}
 
Thanks a lot for the help !