I’m trying to set a default Sales Person on the Sales Order when an order is created. By default, it will pull in the Sales Rep associated with the customer.
I want to change this to a different default Sales Rep if the defaulted Sales Rep isn’t of a certain role code.
To do this, I was scanning the new order row, creating a broken out list from SalesRepList (which is notoriously ‘~’ seperated) and compare it to a list of approved role codes. To my surprise, for a brand new created order, SalesRepList is empty, yet it still fills out a value for SalesRepCode1.
my code, which is partially how I found out it’s empty:
//look at incoming SalesRepList (~ delimited) and if none are Role Code "Commissions", add the Arthrex sales rep in lieu of the defaulted sales rep
var salesRepString = ttOrderHed.Where(r=> r.Added())
.Select(r=>r.SalesRepList)
.FirstOrDefault();
if(salesRepString != null)
{
//split the string into a list of Sales Rep Codes on ttOrderHed
var salesRepList = salesRepString.Split('~').ToList();
if(salesRepList.Count>0)
{
//create a list of Commissions sales rep codes and compare out salesRepList to it.
//if we don't have one in our list, we will add Arthrex as the sales rep
var roleCodeList = Db.SalesRep.Where(r=>r.Company == Session.CompanyID
&& r.RoleCode == "Commissions")
.Select(r=>r.SalesRepCode)
.DefaultIfEmpty()
.ToList();
//if the salesRepList does not contain any of the commissions reps, add to ttOrderHed.SalesRepList as default
if(!salesRepList.Any(x=>roleCodeList.Any(y=> y==x)))
{
//set ttOrderHed.SalesRepList = "ARTHREX";
string content = JsonConvert.SerializeObject(salesRepString, Formatting.Indented);
this.PublishInfoMessage(content,Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "OrderHed", "DataDirectiveStd");
//salesRepCode = "ARTHREX";
content = JsonConvert.SerializeObject(roleCodeList, Formatting.Indented);
this.PublishInfoMessage(content,Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "OrderHed", "DataDirectiveStd");
}
}
}
A trace also indicates SalesRepList is empty on a new order.
So; for a newly created order, is this field always empty? I will need to test if this is the case (which it’s probably not) for orders created from quotes as well.
I am just looking for a way to set a defaulted sales person if the customer sales rep is not of a certain role code. Thanks