We’ve got the ToUpper and ToLower C# functions in Epicor, but ToTitleCase doesn’t seem to work in my data directive (trying to automatically change all Customer Names to Title Case)…
The StackOverflow article mentions using System.Globalization - Is that my issue? I added a CustomCode widget, set Using’s and pasted in the ChatGPT code (which doesn’t work, I’m thinking due to the setting the customer name variable).
Seems like this should be super simple for a real programmer (e.g. not me!).
You need to call it slightly differently. I tested this and it works fine - modify to suit your need. It does require a using statement -
using System.Globalization;
var shipVia = ds.ShipVia.Where(r => r.RowMod == "U").First();
var origDesc = shipVia.Description;
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
var newDesc = ti.ToTitleCase(origDesc);
shipVia.Description = newDesc;
Edited to add that this doesn’t work if the string is already all in CAPS. So in that instance you’d just need to call .ToLower() first, then the ToTitleCase().
@markdamen - Thanks for the help! I don’t totally understand what I’m doing, but I got it to compile. It doesn’t capitalize the name when I do an update, though…
var custName = this.Db.Customer.Name;
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
var newName = ti.ToTitleCase(custName);
custName = newName;
I changed the syntax to match yours better, but it errored out since the Customer table didn’t have RowMod. I removed it the where clause, and it compiled but didn’t proper case the customer name.
Nice trail running profile pic, btw! We’ve got some great races here in New England if you’re ever in this part of the world.
Thanks so much! I did a trace on creating a new Customer, and the first place the customer name is set is on the CheckCreditHold BO. I added a pre BPM there, it compiled (woohoo, thank you!!!), and the message box shows it’s being triggered. Unfortunately, the Name still stayed lowercase or upper case (guessing that setting the name isn’t part of that BO’s function).
I moved the BPM over to the Update BO, and it works!
I might still need to do it in a data directive, though. We’ve got an address verification BPM on the Customer Update BO from Avalara which capitalizes the address, unless I can add this afterward.