When to use a BO

Good morning in the code below, which I’m using in Custom Function Code is there a way to update the two tables below using BO or is using the Db the best or simplest way to make these updates?

        var partOprs = this.Db.PartOpr.Where(po => po.Company == Session.CompanyID &&
                                                    po.PartNum == ipPartNumber &&
                                                    po.OprSeq == ipOprSeq &&
                                                    po.OpCode == ipOpCode);

        foreach (var partOpr in partOprs)
            partOpr.EstUnitCost = ipNewEstUnitCost;
            partOpr.VendorNum = ipNewVendorNum;
            partOpr.PurPoint = ipNewPurPoint;

        var jobOpers = this.Db.JobOper.Where(jo => jo.Company == Session.CompanyID &&
                                                    jo.PartNum == ipPartNumber &&
                                                    jo.OprSeq == ipOprSeq &&
                                                    jo.OpCode == ipOpCode &&
                                                    jo.OpComplete == false &&

        foreach (var jobOper in jobOpers)
            jobOper.EstUnitCost = ipNewEstUnitCost;
            jobOper.VendorNum = ipNewVendorNum;
            jobOper.PurPoint = ipNewPurPoint;

        opSuccess = 1;
    catch (Exception ex)
        opErrorMsg = ex.Message;
        opSuccess = 0;

There is no BO to update PartOpr. You should be checking out the part via engineering workbench and checking it back it.

1 Like

Okay would you be able to point me to an example of getting the part so I can update the partOpr values

Did you make a trace of checking out the part, making the change, then checking it back in via engineering workbench?

1 Like

That being said, if you are just updating some reference type fields, you should likely be fine. (I didn’t look at your code.) But if you are messing with fields that impact or could possibly impact business logic, do it the right way.

Here’s a link for the checkout part of it.

Also, working with the db context directly ignores all Field Security and if you have a Method Directive on that object, it won’t fire.

1 Like