- 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-31-2023 09:21 AM
Hi @Amol Pawar,
Updated scripts:
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).toString().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);
g_form.addErrorMessage('You can add only two secondary SPOCs');
}
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-31-2023 08:32 PM
Hi @Sagar Pagar ,
A small change in last few lines and it worked 😊
}
g_form.setValue(add_secondary_spocc, mynewlist);
g_form.addErrorMessage('You can add only two secondary SPOCs');
}
}
Thank you so much!
Amol.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 10:07 PM
Hi @Amol Pawar,
Yes. it should be your mynewlist array. as it contains only 1st two selected users.
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar