Before insert BR

Ayushi Saxena
Tera Contributor
Hi All,
 

Can anyone help me to figure out there is before insert BR to update the shipping instruction field value append with the purchase reason field value.

 

There are 3 different types values in purchase reason field for one of the case it's working fine for 1-2 case it's not working.

 
 
(function executeRule(current, previous /*null when async*/ ) {
    function toTitleCase(str) {
        return str
            .toLowerCase()
            .replace(/[^a-zA-Z0-9 ]/g, '') // Remove special characters but keep spaces
            .replace(/\b\w/g, function(match) {
                return match.toUpperCase(); // Capitalize first letter of each word
            });
    }
    var titleCaseReason = toTitleCase(current.purchase_reason.toString());
    //var originalShippingInstruction = '';
    var originalShippingInstruction = current.u_shipping_instructions.toString();
    //current.u_shipping_instructions = ' ';
    current.u_shipping_instructions = titleCaseReason + ': ' + originalShippingInstruction;
})(current, previous);