Restrict Vendor Record with Long Name Using Client script

Function for restricting the user from creating a vendor name that is no longer than 74 characters.

If a user tries editing a vendor record that already has more than 74 characters, an alert is thrown, and the user can only save the record if the name is shortened to 74.

Applicable only to company-type Vendors.

The below function can be used in client script’s fieldChanged() and saveRecord() entry points to restrict vendor records from saving if their name is longer than 74 characters.

let company = scriptContext.currentRecord.getValue(‘isperson’);

if (company === ‘F’) {

let vendorName = scriptContext.currentRecord.getValue({

              fieldId: ‘companyname’

        }); 

let vendorNameCount = vendorName.length;

        if(vendorNameCount > 74){

              let countRem = vendorNameCount – 74;

              alert(“Company name can’t be greater than 74 characters. Reduce “+countRem+” character(s).”);

} else{

return true;

}

}

Leave a comment

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