Client Script needed on change Script needed

Saib1
Tera Guru

Hi All,

 

My Requirement 

 

Add Group Members , this field should allow only if they added more than 20 members in the list (This will allow only to select more than 20 members to be added in group)

Saib1_0-1730975175350.png

 

Add Group Members field need to be added (This will allow only to select more than 20 members to be added in group)

1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage
Giga Sage

Hi @Saib1 Please try below.

 

function onSubmit() {
    var groupMembers = g_form.getValue('add_group_members'); 
    
    if (groupMembers) {
        var memberCount = groupMembers.split(',').length;

        if (memberCount < 20) { /
            alert('You must select at least 20 members to add to the group.');
            return false; 
        }
    } else {
        alert('No group members selected. You must select at least 20 members to proceed.');
        return false; 
    }
    
    return true; 
}

 Please mark my answer correct and helpful if this works for you.

View solution in original post

5 REPLIES 5

Runjay Patel
Giga Sage

Hi @Saib1 ,

 

You can write onsubmit client script and use below logic to prevent the form submission.

var str = g_form.getValue('add_group_members');
if(str.split(',').length <20)
return false;

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

I need it onChange 

 

Onsubmit will not work because i am doing this in below

 

Saib1_0-1730981238730.png

 

Hi @Saib1 ,

 

How you can, you have to select user 1 by 1 and if you run script on onchange the it will be less than 20 user at a time. What is your business requirement.

 

Also you can use same script in onchange also just remove the return line and display message or clear field value.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

 

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

@Runjay Patel 

 

I tried the below script it was giving me the length as '1' if i did not select any value on the list collector

 

Saib1_0-1730985880311.png

 

 

 

 alert("hello");
 var str=0;
var str = g_form.getValue('add_group_members');
if(str.split(',').length <20)
alert(str.split(',').length);
 alert('This will allow only to select more than 20 members to be added in group');
 return false;
}