Function advice/critque

CallService is better-encapsulated … it’s simpler syntax and handles disposing the object when you’re done. Use that one.

2 Likes

Something that might be helpful for prototyping, especially if you want to use mainly widgets for the BO calls in your functions, at the risk of a little self-promotion: I’ve been using my own Python library for prototyping Epicor Functions. It’s been pretty helpful to me. e.g.,

def quote_update_price(epi, quotenum, quoteline, newprice):
    # this is a rough draft of the function created in Epicor
    print("Updating price...")
    r = epi.Erp.BO.QuoteSvc.GetByID(QuoteNum=quotenum)
    r.raise_for_status()
    ds = r.json()['returnObj']
    for i, l in enumerate(ds['QuoteDtl']):
        if l['QuoteLine'] == quoteline:
            quoteline = i
            break
    ds['QuoteDtl'][quoteline]['DocDspExpUnitPrice'] = newprice
    ds['QuoteDtl'][quoteline]['RowMod'] = 'U'
    r = epi.Erp.Bo.QuoteSvc.GetDtlUnitPriceInfo_User(skipDiscLookup=True, preserveAmt=True, pIsGridPasting=False, pChangedByUser=True, ds=ds)
    r.raise_for_status()
    ds = r.json()['parameters']['ds']
    r = epi.Erp.BO.QuoteSvc.Update(ds=ds)
    r.raise_for_status()
    print("Done.")

It helps me more quickly figure out which BOs and services I need to touch and which fields are required versus optional for each call. (Like that call to QuoteSvc.GetDtlUnitPriceInfo_User() in the example above.)

Something like this? It seems to work the same for the very extensive and thorough testing I’ve done.

Erp.Tablesets.PartTableset partTS = new Erp.Tablesets.PartTableset();

try
{
  this.CallService<Erp.Contracts.PartSvcContract> (boPart => 
  {
    boPart.GetNewPart(ref partTS);
      var boPartRow = partTS.Part[0];
      boPartRow.PartNum = partNum;
      boPartRow.PartDescription = partDesc;
      boPartRow.NonStock = true;
      boPartRow.MfgComment = "WS";
      boPartRow.ClassID = "IS";
      boPartRow.IUM = "EA";
      boPartRow.PUM = "EA";
      boPartRow.SalesUM = "EA";
    
    boPart.ChangePartTypeCode(partType, ref partTS);
    boPart.GetNewPartRev(ref partTS,partNum,"","");
      var boPartRev = partTS.PartRev[0];
      boPartRev.RevisionNum = partRev;
      boPartRev.RevShortDesc = "Original Rev";
      boPartRev.RevDescription = "Original Rev";
      boPartRev.Plant = "MfgSys";
    
    boPart.ChangePartRevApproved(true,true,ref partTS);
    boPart.Update (ref partTS);
  });  
}
catch 
{
  output = "Dohh!";
}
2 Likes