Script include for record producer variable length

Joe Weisiger
Giga Expert

Hello,

I have multiple similiar record producers that all require a common variable 'Description' to be a minimal of 251 characters.  I also need to validate that 'Description' is not the same as 'Short Description'.

I wrote an onChange catalog client script on the description field that works for this, but I want to see if it would be smarter to create a script include with the logic for length so that it can be shared across all required forms to pass in the length so it can be dynamic as a parameter.

How would I go about creating the script include and how should I call it in the record producer?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {
          return;
    }

    //Verify that Short Description and Description are not the same

        var title = g_form.getValue('short_description');
        if(title == newValue)
        {
                  alert('Description cannot be the same as the Short Description.  Please enter additional information.');
                  g_form.clearValue('description');
        } 
	
	//Verify that Description is at least 250 characters


       var short_desc = g_form.getValue('description');
       if(short_desc.length < 251){


                  alert("Please enter a description longer than 250 characters.");

        }

}