SalesRepList empty, but SalesRepCode1 exists?

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

Is this a post process bpm on SalesOrder.Update?

I don’t work with bpm/customizations so it is difficult for me to tell just from the code, I can tell you at least that in my local environment after saving the field OrderHed.SalesRepList is populated on the DB.

It’s on an in transaction data directive. So that field is filled out when you create a new sales order?
But maybe that’s the trick; post processing bpm might have it available

If I’m reading the code correctly the UI interacts with individual SalesRepCodeX fields, it is only after saving in OrderHedAfterUpdate that SalesRepList is constructed from concatenated SalesRepCodeX fields.

You could just use SalesRepCode1/2/3/4/5 directly if they are available on your directive, or the post processs bpm if it works better. Like I said I don’t work much with bpms so not sure of the differences or best uses.

1 Like

I think you’re right. I’ll have to approach it a little differently then. Thank you!

Hey Aaron. I’m running into this same issue. Using a data directive trying to update the Sales Person on an order. Did you find a solution to this or did you have to scrap the data directive?