How can i restriction the filed value by using client script.

JMR2
Mega Expert

Hi all,

I have requirement, can I restrict the field value by using client script.

thanks in advance.

13 REPLIES 13

Hi Amlan,

thank for your response, but I"m still Unable to stop the user from typing and at end user is getting error message post after going to next filed. i need to restrict user from typing when he is in control of same field.So it should be something different then regular client scripts.

Thanks,

 

Raj68
Mega Guru

Hi JMR,

write onLoad client script to restict the field value,for detail go through below link:

https://community.servicenow.com/community?id=community_question&sys_id=44af0365dbdcdbc01dcaf3231f96198b

NOTE: Mark correct or helpful if it helps you.

 Warm Regards,

Raj patel

 

SatheeshKumar
Kilo Sage

if you need to restrict user from entering a value on particular field.

 

you can use UI policy to make that field read only, or  use  g_form.setReadOnly('VARIABLE NAME',true); in client scripts.

 

Using UI policy is preferred.

Hi satheesh kumar,

I am trying to restrict the filed values by using configure dictionary, but it is not allow because all ready some records is their. thus why i'm trying on change client scripts. i'm tried below code, but my point is  user wants to enter only 10 character not more than.

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

var r=g_form.getValue('short_description');
var l=r.length;
if(l>10)
{
var t=r.slice(0,10);
g_form.setValue('short_description',t);
g_form.showFieldMsg('short_description','....................');
}

oh..ok. it is not possible to do this functionality.  i too had faced this situation and followed the same onchange method and errror message

 

else

you need to create a macro/widget variable to do that.

check below link for more details

 

-satheesh