Before insert BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2025 12:50 AM - edited 06-16-2025 02:55 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2025 02:42 AM
Hi @Ayushi Saxena ,
Please rephrase your problem statement. It is a bit confusing. When exactly it is working and when it is not working? With clear information it would be easier to provide the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 03:00 AM
@Anil Nemmikanti,
Can you please go through again. I have updated
- 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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 09:23 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader