How to restrict the form to be submitted when the script condition matches and to retain oldValue.

1_DipikaD
Kilo Sage

Hi All,

I am passing a validation when the below script condition matches through onchange Client script. But at the same time I need to restrict user from submitting the form with if the value of the justification field is less than 60.Also if user does any changes to a existing value and try to submit a newValue of less than 60 character, it should not take and the justification field should should retain it's oldValue . I have tried below scripts, onChange is working as expected but not sure how to restrict user from submitting the form with incorrect value without impacting existing value of the field(If form is getting submitted with value length <60). 

Please suggest me on this  what should be best approach to achieve this ? Please let know if you nee more info .

 

Thank You

 

 
21 REPLIES 21

JulianP32954866
Tera Expert

My way.

 

Put this into a variable set so you can add to any items that need it

onLoad script

declare g_form.isError = [];

It will contain JSON objects where the key is the variable name and the value is true/false

 

Have a function in a Catalog Client Script (non isloated) called

updateIsError

The function looks at the g_form.isError array and determines if a key for that variable exists and makes it either True or False - depending on if there is an error or not.

 

g_form.isError = [{"project_start_date":true},{"project_end_date":false}];

 

Then an onSubmit that looks at the array g_form.isError and then simply adds a message to tell the user there are errors for any variable, and if so, stops the submission.

 

Means you write an onChange to give immediate feedback to the user, stop submission if required and do not duplicate your code.

 

 

Or failing that, create an onLoad Catalog Client Script (non isolated) that has a function you can call for each item of code you want to run (or a Catalog Client Script for each function).  Call the relevant function via an onChange for immediate feedback and then in an onSubmit you call all the same functions and stop submission if required.

here is an update set that creates a Variable Set which can then be added to any Catalog Item that needs it

Do your calcs, use the updateIsError to set the value in the object to True (error), false (good)
the onSubmit checks and will stop submission

 

I wrote this a few years ago.  The old portal (CMS) would stop you submitting a form if there were error messages on a variable.  I hadn't used it for ages and was now on the Service Portal and had to create a new item with lots of field validations.  A late final check and I was horrified to find I could submit with a plethora of "errors".,  I didn't want to rewrite everything as an onSubmit as well, so a bit of lateral thinking and came up with this.