Is this a system counter or comapny specific (this.Db, NextSequenceCode)?

Hello,

I have been asked to set up autoassign on customer numbers for multiple companies within my Epicor database.

I have it set up for Company ‘ODD’ and it works fine.

I was hoping to just set the method directives to ‘Company Independent’ and have each company use their own autoassigned number.

My problem is, it looks like the below code uses a system wide counter (I may be mistaken).

When I try to autoassign in a different company ‘OVR’, it grabs the next number from company ‘ODD’.

I didn’t try to rest the number in ‘OVR’ because I didn’t want to mess up ‘ODD’ unless someone here tells me that the counters are independent from each other but just set the same accidentally.

Would someone on here please look at the below code and tell me if it is system wide or company specific for holding the counter?

If it is system, is there a way to make it company specific?

If not, is my best shot to just set it to ‘Company Dependent’ and recreate it on the other company? (If this is a system counter, it may not help doing that way).

Any and all help is truly appreciated!

/*if the customerID = "AutoAssign" just retrieve the next number
if the customerID = "AutoSet" set the new next value to the number found in the customer name.
*/
foreach (var MyCust in ttCustomer.Where(MyCust => MyCust.Added()))
  {
    var nv = new NextValue(Db);
    string NextSequenceCode = "NextCustomer"; //change this to the value you want to retrieve
    NextValueReset = 0; //prevents later message from showing
    
    switch (MyCust.CustID)
      {
        case "AutoAssign":
          int nextVal = nv.GetNextSequence(NextSequenceCode);
          string testCustomer = "zzz";
          
          do{
            testCustomer = (from c in Db.Customer where c.Company == Session.CompanyID && c.CustID == nextVal.ToString() select c.CustID).FirstOrDefault();
            if(testCustomer == null){
              //the following line will create a customer ID that starts with C with zero filled 6 digit number
              MyCust.CustID = string.Format("{0:00000}",nextVal);
            }else{
              nextVal = nv.GetNextSequence(NextSequenceCode);             
            }
          }while(testCustomer != null);
            
          NextValueReset = 0; //prevents later message from showing
          break;
          
        case "AutoSet":
          /*Here we can reset the next customer*/
          // first we have to do call the getnextsequence,
          // just in case this is the first time it is being called so that it creates the sequenceint Junk = nv.GetNextSequence(NextSequenceCode);
          //now that we are sure it exists, we will set the next sequence value
          NextValueReset = Int32.Parse("0" + MyCust.Name);
          if (NextValueReset != 0) NextValue.SetSequenceCurrentValue(this.Db, NextSequenceCode, NextValueReset);
          MyCust.CustID = "";
          MyCust.Name = "";
          break;
      }
}

Can you just append the company ID to that?

There is a global one and a company specific one. In the same library I believe

Search the forum @timshuwy has an example of both I believe

I have never understood this request. I just don’t see the business value in it other than that’s how we used to do it. :man_shrugging: No shade meant for you Shawn! Just venting…

1 Like

@josecgomez
Hey,

I didn’t find one from Tim but I found where you referenced it, I think.

You recommended replacing parts of the code in my original post with this:

using (var libCompanySequence = new Erp.Internal.Lib.CompanySequence(Db))
{
           var nextCustID= libCompanySequence.GetNextCompanySequence(Session.CompanyID, "CustIDSeq").ToString();
}

You also said to: Bring in Reference Erp.Internal.Lib.Shared.

I did that no problem.

My question is, how do you use it in the code?

Do I paste your code right below the foreach?

Then do I use the nextCustID you created in place of all the NextValueReset?

I am working on wrapping my brain around it but C# doesn’t come naturally to me yet.

I wish there was a good tutorial on the basics of C# in Epicor specifically…

If I puzzle it out before you reply, I will post my results here for anybody else trying to get this going.

I appreciate your help.

Without all of you, this would be so much harder!

2 Likes

There is also a BPM cookbook on Epicweb as well as customization guides that have snippets in there to take what Jose posted above and apply it to Epicor.

@hkeric.wci also wrote a post on looking at the code generated from using widgets in BPMs or data directives and that also may help you try and understand more about coding in Epicor.

Documentation (epicor.com) - technical reference guides

Documentation (epicor.com) - user guides