How to set all field values in lower case on catalog items

Phanindra N
Tera Guru

I want all the field values on catalog item in lower case, since there are around 50 fields on form it is not a good idea to write all 50 on change client scripts an make each field content to lower case. This is tedious and have performance impact.

 

Is there any other way to implement this.

Thanks in advance.

2 REPLIES 2

Vishnu kumar R
Tera Guru

Hi @Phanindra N ,

 

You can try creating On Submit catalog client script, So it will be processing only on submission.

 

Please mark helpful if it helped with your query,

Thanks.

Sandeep Rajput
Tera Patron
Tera Patron

@Phanindra N Please see if the following script works for you.

 

function onSubmit() {
    // Get all field names
   
    // Loop through the fields to get their values
    for (var i = 0; i <  g_form.elements.length; i++) {
        var fieldName = g_form.elements[i].fieldName;
        var fieldValue = g_form.getValue(fieldName);
      // Check if the field value exists
        if (fieldValue) {
            // Convert the value to lowercase and update the field
            g_form.setValue(fieldName, fieldValue.toLowerCase());
        }   
    }       
    // Optional: Perform additional actions or validations based on field values
    // Return true to allow submission, or false to block submission
    return true;
}

Source: https://www.servicenow.com/community/itom-forum/how-to-get-all-fields-which-are-available-on-form-on...