Java Script Validation in Workflow

This method no longer works with later versions of HR.Net. See update.

Screen validation has been mastered by me a long time ago and we are using it all over the place.
But workflow screen has not been properly validated before. Today I digged through the page code and discovered the way to do workflow screen validation. It works the same way as screen validation, but you need to override function with different name. See the example below:

var orig_ValidatorOnSubmit = window.ValidatorOnSubmit;

 * If this function returns false, the workflow is not going to be saved. 
 * Beware that you need to show an error message to user, otherwise they would be 
 * left with non-working form and no way of knowing about the problem 
 * If this function returns true, form is going to be saved fine.

window.ValidatorOnSubmit = function(){
  var ErrMsg ='';
  var validate = true;
  // your custom validation goes here
	if (!validate){
		return false
	return orig_ValidatorOnSubmit();
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

9 Responses to Java Script Validation in Workflow

  1. Dan Hutson says:

    This is a great piece of coding, and works better than the one Vizual provide for workflow validation. One thing I am having trouble is if I have a repeating section and want to validate these fields only if a row has been added. Have you come across a way of doing this? If the row doesn’t exist and you try to validate the display value of the fields an error occurs and the script stops running, which means the form will submit with no further validation. Any help would be greatly appreciated. Kind regards, Dan

    • admin says:

      Dan, no I have not looked on validation of repeating sections. My approach would be to find out how the new rows are added and try to find out names for them, or some way to access these new fields via document.GetElementById(). Then check if there is anything in the field and do further validation.

      If I get to validate the repeating section, I’ll post it here for sure.

  2. Dan Hutson says:

    I’ve used your script to export the full HTML from a workflow with a repeating section and each label and field is suffixed with xxROWxxn, where n = 0,1,2,3…. etc.

    Could I use a similar script that you used for hiding fields based on a radio button where I can loop through the repeating section rows?

  3. Dan Hutson says:

    I managed to do it!

    var ErrorText = "";

    function check_repeating_section(field_name, longfield_name)
    var field;
    var validate = true;
    // loop to go from zero, until we no longer can find an field
    for (var i = 0; i != -1; i++)
    field = document.getElementById(field_name + "xxROWxx" + i.toString() + "_txtInput"); //get field by ID
    if (field === null) //check if field exists
    return; // if no field, we exit the function
    r = i + 1
    if(field.value === "")
    ErrorText += "Please enter a value for " + longfield_name + " in row " + r.toString() + ". \n";
    validate = false;
    } //end of for-loop

    return validate // if field there, we return it's value

    if(!check_repeating_section("CourseName", "Course Name"))

  4. Dan Hutson says:

    Me again!

    Is it possible to distinguish between when a workflow form is being submitted and when the user is saving it to their drafts folder?

    We have times when the manager does not have certain information and therefore wants to save the form rather than submit it, but the page validation script still fires in this instance.



  5. Pingback: Java Screen Field Validation | Vizual HR.Net Development: Tips, Tricks and Work-Arounds

Leave a Reply

Your email address will not be published. Required fields are marked *