Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 03:11 AM
try this and see if purchase reason is null
Is purchase_reason a choice value?
if yes and you want label then use this
current.purchase_reason.getDisplayValue()
(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 purchaseReason = current.purchase_reason ? current.purchase_reason.toString() : '';
var titleCaseReason = toTitleCase(purchaseReason);
var originalShippingInstruction = current.u_shipping_instructions ? current.u_shipping_instructions.toString() : '';
// Only update if purchase reason is present
if (titleCaseReason) {
current.u_shipping_instructions = titleCaseReason + ': ' + originalShippingInstruction;
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader