I’ve been working with a few clients recently extending the capabilities of their ServiceDesk Plus Service Catalogue templates. On a number of occasions the issue of time wasted owing to incorrect data being logged has arisen. A couple of these issues related to the logging of data such as making sure numeric data is consistent and date validation. Often these issues arise as a result of collecting data, in a new starter process for example.    For one client the logging of an Employee ID number was of particular importance. In collecting this data it was important to verify that the length of the ID number was correct. As an added complication they also used different length ID numbers for different sites in the business. In truth this issue was easily handled using the scripting capabilities offered by the Field and Form Rule capabilities of ServiceDesk Plus.    The field and Form Rules already give an example of how to perform numeric validation:

All the customer needed to do in this instance was to check if the number entered was 4 or 6 digits long depending on the Site of the requester. To achieve this we simply modified the script to check the numeric range, and therefore length, of the data entered into this field. The “ServiceReq_601_UDF_LONG1” variable represented the name of the custom field that had been created to record the Employee ID number (the script tool shows this field name based on the field label name so it’s easy to locate and identify):

var numericFieldVal = $CS.getValue("ServiceReq_601_UDF_LONG1");
/*checks if numeric fields is non-empty*/ 
if (numericFieldVal!=='')
{   
    /*checks if numeric field's value is numeric constant*/
    if (jQuery.isNumeric(numericFieldVal))  
    {       
        /*parse string to numeric value*/  
        var numericValue = parseInt(numericFieldVal);


       /* i.e. test if less than 4 characters */
        if (numericValue < 1000)        
        {
            alert("Value of xyz cannot be less than four digits"); 
            /*stop form submission*/ 
            $CS.stopFormSubmission(); 
        }  
             /* i.e. test if greater than 4 characters */  
             if (numericValue > 9999)        
        {
            alert("Value of xyz cannot be more than four digits"); 
            /*stop form submission*/ 
            $CS.stopFormSubmission(); 
        }    
    }
    else
    { 
        alert("Enter a valid numeric constant");
        /*stop form submission*/    
        $CS.stopFormSubmission();  
    }
} 

All we then need to do was apply this script to a Field and Form Rule when submitting the ServiceDesk Plus form or to have the check performed when the form was being edited when the user was entering data into the Employee ID field. By having separate Rules that used the condition check of the Site field we could use the script, with appropriate modifications, to test for entries of 4 digit and 6 digit Employee ID numbers.   For the purists I could have simply checked the length of the numerical input using the Javascript ‘length’ element and using this in the ‘if’ statement tests:

numericLen=numericFieldValue.length;

However, as a first pass and without the need to Google, this did the job ;0)   I’ll provide an example of Date based verification example in Part 2.   Enjoy!

This article is relevant to:
Service Desk

You may be interested in these other recent articles

ManageEngine ServiceDesk Plus On-Premise Build Release Information

28 June 2022

Summary details of the current Build Release information for ManageEngine ServiceDesk Plus. To safely upgrade your current instance of ManageEngine ServiceDesk Plus please refer to…

Read more

ManageEngine Endpoint Central (formerly Desktop Central) On-Premise Build Release Information

27 June 2022

Summary details of the current Build Release information for ManageEngine Endpoint Central. Note: Desktop Central changing its name to Endpoint Central will not affect the…

Read more

ManageEngine ServiceDesk Plus Cloud Build Release Information

Summary details of the current Build Release information for ManageEngine ServiceDesk Plus Cloud Edition. All upgrades are performed by the Zoho Cloud team. Should you…

Read more

Get to building your business apps with the new AppCreator

9 June 2022

ManageEngine’s new low-code application development tool Creating an application, building one and deploying it can be expensive and time consuming as you have to make…

Read more

Endpoint Central’s Endpoint Security

31 May 2022

Endpoint Central (formerly Desktop Central) not only got a name change but has also introduced Endpoint Security to help organisations keep their endpoints secured. According…

Read more