Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting mixed signals re Sage API's

Status
Not open for further replies.

NRHarding

Programmer
Feb 3, 2016
1
AU
Hey All,

I'm just delving into the world of working with the Sage API's and Stephen Smith's blogs have been great, but the problem is I can't seem to get any consistent information on Order Entry. Okay, so the scenario is this, basically I want to be able to use the Sage API to enter in Order Entry and eventually Purchase Order data from my program, however, should I be programming in VB.Net or C#? I checked out the Sage Development Program, but it mention's all other Sage products except for Accpac 300, which we use across 5 branches.

Is anybody able to point me in the right direction as to where I should be looking, or even a dead simple example in either vb.net or c# to enter an order into sage accpac via the accpac.advantage or com api or any other avenue you can suggest?

Seriously, your help would be AMAZING, and I would be beholden to you!

Cheers :)

Nick.
 
VbDotNet is better, because you can record VBA macros and convert them to DotNet much easier than C#. Since you can use nearly every add-on library in both languages, there's no advantage to C#.
 
VB.NET or C# is your personal preference. I used VB.NET then moved to C# and really enjoy C# in many ways.

For integration purpose, VB.NET or C# is the same, since the code will be translated to IL by .NET framework anyway. The reference to ACCPAC.ADVANTAGE is no different than ACCPACCOMAPI, only coding is different if you use either. I prefer ACCPACCOMAPI since ACCPAC.ADVANTAGE relies on ACCPACCOMAPI anyway, you bring in another layer with ACCPAC.ADVANTAGE, if you program against it. I believe ACCPAC.ADVANTAGE can be used in web application, but I might be wrong, since I avoid using it.
 
There have been posts on this site in C# and in VB.Net. Adding orders to order entry is, mechanically, no different than entering A/R invoices, for example. There are some subtle things that order entry does.

Now - I happen to have some C# code for entering orders. I can't show it all because it isn't my code but I can show you the non-customer specific stuff.

Note: This is not my code. I didn't write it. It might have bugs. It is most certainly incomplete.

Use at your own risk.

Code:
        /*********************************************************************/
        static public bool OrderSetup()
        /******************************************************************/
        {
            try
            {
                CustId = "";
                ShipTo = "";
                Locn = "";
                ShipVia = "";
                PoNbr = "";
                Descr = "";
                Ref = "";
                Addr1 = "";
                Addr2 = "";
                Addr3 = "";
                Addr4 = "";
                City = "";
                State = "";
                Zip = "";
                Contact = "";
                Phone = "";
                Fax = "";
                Email = "";
                Plist = "";

                TaxGroup = "AVATAX";


                AccpacViews.oDBLinkCmp.OpenView("OE0520", out oOrderHeader);                // OEORD5header
                oOrderHeaderFields = oOrderHeader.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0500", out oOrderDetail);                // OEORD5detail1
                oOrderDetailFields = oOrderDetail.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0508", out oOrderDetailSerial);          // OEORD5detail6
                oOrderDetailSerialFields = oOrderDetailSerial.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0501", out vOE0501);                     // OEORD5detail8
                fldOE0501 = vOE0501.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0507", out oOrderDetailLot);             // OEORD5detail7
                oOrderDetailLotFields = oOrderDetailLot.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0740", out vOE0740);                     // OEORD5detail2
                fldOE0740 = vOE0740.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0180", out vOE0180);                     // OEORD5detail3
                fldOE0180 = vOE0180.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0526", out vOE0526);                     // OEORD5detail4
                fldOE0526 = vOE0526.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0522", out vOE0522);                     // OEORD5detail5
                fldOE0522 = vOE0522.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0502", out vOE0502);                     // OEORD5detail9
                fldOE0502 = vOE0502.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0504", out vOE0504);                     // OEORD5detail10
                fldOE0504 = vOE0504.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0506", out vOE0506);                     // OEORD5detail11
                fldOE0506 = vOE0506.Fields;

                AccpacViews.oDBLinkCmp.OpenView("OE0503", out vOE0503);                     // OEORD5detail12
                fldOE0503 = vOE0503.Fields;

                oOrderHeader.Compose(new object[] { oOrderDetail, null, vOE0180, vOE0740, vOE0526, vOE0522 });
                oOrderDetail.Compose(new object[] { oOrderHeader, vOE0501, vOE0503, vOE0502, oOrderDetailSerial, oOrderDetailLot });
                vOE0180.Compose(new object[] { oOrderHeader, oOrderDetail });
                vOE0526.Compose(new object[] { oOrderHeader });
                vOE0522.Compose(new object[] { oOrderHeader });
                oOrderDetailSerial.Compose(new object[] { oOrderDetail });
                oOrderDetailLot.Compose(new object[] { oOrderDetail });
                vOE0501.Compose(new object[] { oOrderDetail });
                vOE0502.Compose(new object[] { oOrderDetail, vOE0504, vOE0506 });
                vOE0504.Compose(new object[] { vOE0502 });
                vOE0506.Compose( new object[] {vOE0502});
                vOE0503.Compose( new object[] {oOrderDetail});

            
            }
            catch (Exception ex)
            {
                if (AccpacViews.oSession.Errors.Count > 0) { AccpacViews.ErrorMsg = AccpacViews.oSession.Errors.Item(0); }
                else { AccpacViews.ErrorMsg = ex.Message; }
                return false;
            }
            return true;
        }

        /**************************************************************************************************/
        static public bool AddOrderHeader(string OrderId)
        /**************************************************************************************************/
        {

            /*****************************************************
            ****  Check to see if the order already exists    ****
            ******************************************************/
            try
            {
                oOrderHeader.Cancel(); 
                oOrderHeader.Init();

                vOE0740.Browse("", true);
                vOE0740.Fetch();

                oOrderHeaderFields.get_FieldByName("ORDNUMBER").set_Value(OrderId);
                oOrderHeader.Order = 1;

                if (oOrderHeader.Exists) { AccpacViews.ErrorMsg = "Order Add - Order Already On-File"; return false; }
                oOrderHeader.Order = 0;

                oOrderHeaderFields.get_FieldByName("CUSTOMER").set_Value(CustId);
                vOE0740.Browse("", true);
                fldOE0740.get_FieldByName("PAYMENT").PutWithoutVerification("-32767");
                vOE0740.Browse("", false);
                vOE0740.Fetch();

                oOrderHeaderFields.get_FieldByName("PROCESSCMD").PutWithoutVerification("1");
                oOrderHeader.Process();

                /*****************************************************
                ****  Setup Order Header fields                   ****
                ******************************************************/
                oOrderHeaderFields.get_FieldByName("PONUMBER").set_Value(PoNbr);
                oOrderHeaderFields.get_FieldByName("LOCATION").set_Value(Locn);
                oOrderHeaderFields.get_FieldByName("SHIPTO").set_Value(ShipTo);
                oOrderHeaderFields.get_FieldByName("SHIPVIA").set_Value(ShipVia);
                if (Addr1 != null && Addr1 != "") oOrderHeaderFields.get_FieldByName("SHPADDR1").set_Value(Addr1);
                if (Addr2 != null && Addr2 != "") oOrderHeaderFields.get_FieldByName("SHPADDR2").set_Value(Addr2);
                if (Addr3 != null && Addr3 != "") oOrderHeaderFields.get_FieldByName("SHPADDR3").set_Value(Addr3);
                if (Addr4 != null && Addr4 != "") oOrderHeaderFields.get_FieldByName("SHPADDR4").set_Value(Addr4);
                if (City != null && City != "") oOrderHeaderFields.get_FieldByName("SHPCITY").set_Value(City);
                if (State != null && State != "") oOrderHeaderFields.get_FieldByName("SHPSTATE").set_Value(State);
                if (Zip != null && Zip != "") oOrderHeaderFields.get_FieldByName("SHPZIP").set_Value(Zip);
                if (Contact != null && Contact != "") oOrderHeaderFields.get_FieldByName("SHPCONTACT").set_Value(Contact);
                if (Phone != null && Phone != "") oOrderHeaderFields.get_FieldByName("SHPPHONEC").set_Value(Phone);
                if (Fax != null && Fax != "") oOrderHeaderFields.get_FieldByName("SHPFAXC").set_Value(Fax);
                if (Email != null && Email != "") oOrderHeaderFields.get_FieldByName("SHPEMAILC").set_Value(Email);
                oOrderHeaderFields.get_FieldByName("TAXGROUP").set_Value(TaxGroup);
                oOrderHeaderFields.get_FieldByName("DESC").set_Value(Descr);
                oOrderHeaderFields.get_FieldByName("REFERENCE").set_Value(Ref);
                if (Plist != null) { oOrderHeaderFields.get_FieldByName("PRICELIST").set_Value(Plist); }
                if (OrdDt != null) { oOrderHeaderFields.get_FieldByName("ORDDATE").set_Value(OrdDt); }
                if (ExpDt != null) { oOrderHeaderFields.get_FieldByName("EXPDATE").set_Value(ExpDt); }
                return true;
            }

            catch (Exception ex)
            {
                if (AccpacViews.oSession.Errors.Count > 0)
                {
                    AccpacViews.ErrorMsg = "";
                    for (int n = 0; n < AccpacViews.oSession.Errors.Count; n++)
                    { AccpacViews.ErrorMsg += AccpacViews.oSession.Errors.Item(n) + "\n"; }
                }
                else { AccpacViews.ErrorMsg = ex.Message; }
                return false;
            }
        }

        /**************************************************************************************************/
        static public bool AddOrderDetail(string OrderId, string Item, Int32 Qty)
        /**************************************************************************************************/
        {

            try
            {
                oOrderDetail.RecordClear();
                oOrderDetail.RecordCreate(0);
                oOrderDetailFields.get_FieldByName("ITEM").set_Value(Item);
                oOrderDetail.Process();
                oOrderDetailFields.get_FieldByName("QTYORDERED").set_Value(Qty.ToString());
                oOrderDetail.Insert();
                oOrderDetailFields.get_FieldByName("LINENUM").PutWithoutVerification("-1");

                oOrderHeaderFields.get_FieldByName("OECOMMAND").set_Value("4");
               }

            catch (Exception ex)
            {
                if (AccpacViews.oSession.Errors.Count > 0) { AccpacViews.ErrorMsg = AccpacViews.oSession.Errors.Item(0); }
                else { AccpacViews.ErrorMsg = ex.Message; }
                return false;
            }
            return true;
        }
        /**************************************************************************************************/
        static public bool PostOrder()
        /**************************************************************************************************/
        {
            try
            {
                fldOE0740.get_FieldByName("PAYMENT").PutWithoutVerification ("-32767");      
                vOE0740.Browse( "", false);
                vOE0740.Fetch();

                fldOE0740.get_FieldByName("PAYMENT").PutWithoutVerification ("-1");
                vOE0740.Browse( "", true);

                fldOE0740.get_FieldByName("PAYMENT").PutWithoutVerification ("-32767");
                vOE0740.Browse("", false);
                vOE0740.Fetch();

                oOrderHeaderFields.get_FieldByName("OECOMMAND").set_Value("4");
                oOrderHeader.Process();
                oOrderHeader.Insert();
            }

            catch (Exception ex)
            {
                if (AccpacViews.oSession.Errors.Count > 0)
                {
                    AccpacViews.ErrorMsg = "";
                    for (int n = 0; n < AccpacViews.oSession.Errors.Count; n++)
                    {
                        AccpacViews.ErrorMsg = AccpacViews.oSession.Errors.Item(n) + System.Environment.NewLine;
                    }
                }
                else
                {
                    AccpacViews.ErrorMsg = ex.Message;
                }
                return false;
            }
            return true;
        }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top