Sage 2017 How to insert AR Customer into Sage with C#

Does anyone have a sample C# example of how to insert a customer into the AR Customers section of Sage 2017 ?

I have the Visual Basic macro sample, but it looks so complicated, don't know where to start.

  • public static AccpacView ArCustomer;
    a4wLink.OpenView("AR0024", out ArCustomer);
    a4wLink.OpenView("AR0400", out ArCustomerOpt);
    ArCustomer.Compose(new object[] { ArCustomerOpt });
    ArCustomerOpt.Compose(new object[] { ArCustomer });


    static string MakeCustomer(OrderResponseDetailHigh order, bool bEbay, bool bJet, bool bAmazonCanada, bool bAmazon, bool bWalmart, bool bAmazonUK, bool bAmazonMX, string sCustGroup, string sAccountSet, string sTerms, bool bGoogleExpress, string sAvalaraSalesPerson)
    {

    string sBrowse = "";
    string sAdd1 = "";
    string sFullName = order.ShippingInfo.FirstName + " " + order.ShippingInfo.LastName;
    if (order.ShippingInfo.AddressLine1 == null)
    {
    sAdd1 = "";
    }
    else
    {
    sAdd1 = order.ShippingInfo.AddressLine1.Replace("\"", "");
    }
    // 11/29/15 Escape names like O'conner
    //sBrowse = "select * from ARCUS WHERE namecust = '" + sFullName.Replace("\"", "") + @"' and TEXTSTRE1 = '" + sAdd1 + "' and codepstl = '" + order.ShippingInfo.PostalCode + "'";
    sBrowse = "select * from ARCUS WHERE namecust = '" + sFullName.Replace("\"", "").Replace("'", "''") + @"' and TEXTSTRE1 = '" + sAdd1.Replace("'", "''") + "' and codepstl = '" + order.ShippingInfo.PostalCode.Replace("-", "").Substring(0, Math.Min(order.ShippingInfo.PostalCode.Length, 9)) + "'";
    //thisShip.PostalCode.Replace("-","").Substring(0,Math.Min(thisShip.PostalCode.Length, 9))

    ArCustReadCS0120.Browse(sBrowse, true);
    ArCustReadCS0120.InternalSet(256);
    if (ArCustReadCS0120.Fetch())
    {
    return ArCustReadCS0120.Fields.FieldByName["idcust"].get_Value().ToString();
    }
    else
    {
    //3 first name, 3 last name, mi, 000
    // Bill to Name + Address1 + Zip
    string sNewCust = "";
    string sAlphas = "";

    Regex regName = new Regex(@"[^\w\s]"); // No punctuation
    sAlphas = regName.Replace(NoPrefix(sFullName.Trim().ToUpper()).Replace(" ", " "), ""); // Remove extra spaces, too
    Regex regNoNums = new Regex(@"[\d]"); // No digits
    sAlphas = regNoNums.Replace(sAlphas, "").Trim();


    string[] sSplitName = sAlphas.Split(' '); // remove double spaces
    if (sSplitName.Length >= 3) // A middle initial
    {
    sNewCust = ((sSplitName[0] + "XXX").Substring(0, 3) + (sSplitName[2] + "XXX").Substring(0, 3));
    }
    else
    {
    if (sSplitName.Length == 2)
    {
    sNewCust = ((sSplitName[0] + "XXX").Substring(0, 3) + (sSplitName[1] + "XXX").Substring(0, 3));
    }
    else
    {
    sNewCust = (sSplitName[0] + "XXXXXX").Substring(0, 6);
    }
    }

    int i = 0;

    // Find the next open number
    do {
    ArCustReadCS0120.Cancel();
    ArCustReadCS0120.Browse("select * from arcus where idcust = '" + sNewCust + i.ToString("000") + "'", true);
    ArCustReadCS0120.InternalSet(256);
    if (ArCustReadCS0120.Fetch()) i += 1;
    else break;
    } while (true);

    if (order.BillingInfo.AddressLine1 == null) {
    sAdd1 = "";
    }
    else {
    sAdd1 = order.ShippingInfo.AddressLine1.Replace("\"", ""); }

    ArCustomer.Cancel();
    ArCustomer.Fields.FieldByName["idcust"].PutWithoutVerification(sNewCust + i.ToString("000"));
    ArCustomer.Process();

    // Default Group
    //ArCustomer.Fields.FieldByName["idgrp"].PutWithoutVerification("31100");
    ArCustomer.Fields.FieldByName["idgrp"].PutWithoutVerification(sCustGroup);

    ArCustomer.Fields.FieldByName["idacctset"].PutWithoutVerification(sAccountSet);
    ArCustomer.Fields.FieldByName["CODETERM"].PutWithoutVerification(sTerms);

    ArCustomer.Process();
    ArCustomer.Fields.FieldByName["CODESLSP1"].PutWithoutVerification(sAvalaraSalesPerson);
    ArCustomer.Fields.FieldByName["namecust"].PutWithoutVerification(order.ShippingInfo.FirstName + " " + order.ShippingInfo.LastName);
    ArCustomer.Fields.FieldByName["TEXTSTRE1"].PutWithoutVerification(sAdd1);
    ArCustomer.Fields.FieldByName["TEXTSTRE2"].PutWithoutVerification(order.ShippingInfo.AddressLine2);
    ArCustomer.Fields.FieldByName["NAMECITY"].PutWithoutVerification(order.ShippingInfo.City);
    ArCustomer.Fields.FieldByName["codepstl"].PutWithoutVerification(order.ShippingInfo.PostalCode.Replace("-", "").Substring(0, Math.Min(order.ShippingInfo.PostalCode.Length, 9)));
    ArCustomer.Fields.FieldByName["codestte"].PutWithoutVerification(order.ShippingInfo.Region);
    ArCustomer.Fields.FieldByName["codectry"].PutWithoutVerification(order.ShippingInfo.CountryCode);
    ArCustomer.Fields.FieldByName["EMAIL1"].PutWithoutVerification(order.BuyerEmailAddress);
    ArCustomer.Fields.FieldByName["EMAIL2"].PutWithoutVerification(order.BuyerEmailAddress);

    // 05/04/20 Add Walmart AVATAX
    // 03/24/21 Walmart now none
    if (bWalmart)
    //if (bWalmart && sCustGroup != "31111") // 31111 = Walmart Canada
    {
    ArCustomer.Fields.FieldByName["CODETAXGRP"].PutWithoutVerification("NONE");
    }
    else
    {
    /// Old logic
    if (ArCustomer.Fields.FieldByName["codestte"].get_Value().ToString().ToUpper() == "NC")
    { ArCustomer.Fields.FieldByName["CODETAXGRP"].PutWithoutVerification("AVATAX"); }
    else
    {
    if (bAmazonCanada)
    {
    ArCustomer.Fields.FieldByName["CODETAXGRP"].PutWithoutVerification("CAD");
    }
    else
    if (bAmazonUK)
    {
    ArCustomer.Fields.FieldByName["CODETAXGRP"].PutWithoutVerification("UK");
    }
    else
    {
    ArCustomer.Fields.FieldByName["CODETAXGRP"].PutWithoutVerification("AVATAX");
    }
    }

    }


    string resultString = "";
    try
    {
    Regex regexObj = new Regex(@"[^\d]");
    resultString = regexObj.Replace(order.BillingInfo.PhoneNumberDay, "");
    }
    catch { }

    ArCustomer.Fields.FieldByName["TEXTPHON1"].PutWithoutVerification(resultString);

    try
    {
    AddCustomerOpt("SALESTERR", "A");
    AddCustomerOpt("VENREP", "HS");
    ArCustomer.Insert();
    Console.WriteLine(ArCustomer.Fields.FieldByName["idcust"].get_Value() + " " + ArCustomer.Fields.FieldByName["namecust"].get_Value());
    }
    catch
    {
    HandleError("MakeCustomer", "");
    }
    return ArCustomer.Fields.FieldByName["idcust"].get_Value().ToString();
    }
    }

  • 0 in reply to Jay Converse Acumen

    Thank you so much, i will try the above and let you know