- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:41 PM
Hi Experts,
I have a requirement where I need to restrict the users by adding multiple users using the list.
As you can see in the screenshot, here I can add n numbers of users. Can we restrict this to add only 2 users?
If yes, then please reply with a solution.
Thanks in advance,
Regards,
Amol
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:50 PM
Hi @Amol Pawar ,
You can use script below in onchange client script:
var variablename = 'variable name here';
var mylist = g_form.getValue(variablename).split(',');
var maxitem = 2;
if (mylist.length>maxitem){
var mynewlist = [];
for (var i = 0;i<maxitem;i++)
{
mynewlist.push(mylist[i]);
}
g_form.setValue(variablename,mylist[i]);
g_form.showFieldMsg(variablename,'Only 2 items can be entered','error');
}
}
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:49 PM
Hi @Amol Pawar,
Take a look at this solution: Limit values that can be entered on list collector variable
Also, go through this article: Limiting Number of Selections in a List Collector
It will help you to limit user selection in list collector field.
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:50 PM
Hi @Amol Pawar ,
You can use script below in onchange client script:
var variablename = 'variable name here';
var mylist = g_form.getValue(variablename).split(',');
var maxitem = 2;
if (mylist.length>maxitem){
var mynewlist = [];
for (var i = 0;i<maxitem;i++)
{
mynewlist.push(mylist[i]);
}
g_form.setValue(variablename,mylist[i]);
g_form.showFieldMsg(variablename,'Only 2 items can be entered','error');
}
}
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 01:55 AM
Thank you @Rahul Talreja and @Sagar Pagar for your reply. With some minor changes as per requirement, it worked.
Thanks and regards,
Amol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 09:05 AM
Hi @Rahul Talreja and @Sagar Pagar ,
I've used the below code and it's working now but if I add 3rd user, it's removing the first two users and keeping the 3rd one. How can we achieve that it should keep first 2 users and remove the third one after adding?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var add_secondary_spocc = 'add_secondary_spocc';
var mylist = g_form.getValue(add_secondary_spocc).split(',');
var maxitem = 2;
if (mylist.length > maxitem) {
var mynewlist = [];
for (var i = 0; i < maxitem; i++) {
mynewlist.push(mylist[i]);
}
g_form.setValue(add_secondary_spocc, mylist[i]);
g_form.addErrorMessage('You can add only two secondary SPOCs');
}
}
Thanks in advance,
Amol