The CreatorCon Call for Content is officially open! Get started here.

service portal custom widget form validation

divya123
Giga Contributor

hi have one custom widget is there in that multiple input fields are there , for one field if data contains wrong words then on submit the for error message has to come and record should not insert in target table, how can we achieve it  

2 REPLIES 2

Rameswar1
ServiceNow Employee
ServiceNow Employee

Hi, your exact requirement is not very clear from the question here, however, if you are looking for validation on the data filled in on the form, I think the best approach for that would be using a client script (on- submit) instead of touching the widget code. You can make client script run just on the portal by setting the UI type on the client script form.

Community Alums
Not applicable

HI @divya123 ,

What i have understood from your requirement is you want to put a validation on the field/fields on your custom widget. And whenever there is a wrong information being fed, it should show a error message.

So, here is an example of such validation:

Consider this as sudo code and do necessary changes as per the portal code (modify the element names and other conditions based on your requirement)

experiment this in normal form (fulfiler view)

var decodeVersion=g_form.getValue('decode_version');

var codeSafe=g_form.getValue('code_from_safe');

var patt = new RegExp("^[a-zA-Z0-9_]*$");

var isAlphaNumaric=patt.match(codeSafe);

if(isAlphaNumaric)

{

if(codeSafe.length!=4 && decodeVersion!=5)

alert("Please enter only 4 digits");

if(codeSafe.length!=6 && decodeVersion==5)

alert("Please enter only 6 digits");

}

else

alert("Please do not enter special characters.");

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep