C# Creating A New Vendor

Hi everyone!

I've been trying to create a new vendor through the BOI and have run into an issue.  It creates something similar to a "place holder" for the vendor number in the vendor table, but does not fully create the vendor.  For example, when I click on that "place holder" it brings up the screen to add the new vendor but doesn't show any of the information from the database row.  Below is my C# code so far that I've been able to get working to create that "place holder".   My plan is to query the database and populate the vendor number automatically, so the number that i'm populating in the code below will change. 

int TaskID = (int)oSS.InvokeMethod("nLookupTask", "AP_Vendor_UI");
oSS.InvokeMethod("nSetProgram", TaskID);

using (DispatchObject vObject = new DispatchObject(pvx.InvokeMethod("NewObject", "AP_Vendor_bus", oSS.GetObject())))
{
string error = "";
try
{

string vendorNumber = "0096198"; // poNumberGlobal;
object[] vendorNumberPass = new object[] { vendorNumber};
vendorNumber = vendorNumberPass[0].ToString();

successCheck((int)vObject.InvokeMethodByRef("nSetKey", vendorNumberPass), "SetVendorNumberKey");

object[] taxObject = new object[] { "TaxSchedule$", "NONTAX" };
successCheck((int)vObject.InvokeMethodByRef("nSetValue", taxObject), "SetTaxSchedule");

object[] vendorName = new object[] { "VendorName$", "Test User" };
successCheck((int)vObject.InvokeMethodByRef("nSetValue", vendorName), "SetNameValue");

object[] address = new object[] { "AddressLine1$", "Test Address" };
successCheck((int)vObject.InvokeMethodByRef("nSetValue", address), "Address");

successCheck((int)vObject.InvokeMethod("nWrite"), "Write");
}
catch (Exception ex) { MessageBox.Show(Regex.Replace(oSS.InvokeMethod("sLastErrorMsg").ToString(), "'", "")); }


}

  • 0
    There are 2 components of the Vendor Key the first one is a division. Even if you are not using divisions you'll need to set a value of "00"

    Add the following to your script

    object[] divObject = new object[] { "APDivisionNo$", "00" }; // or whatever division you need
    successCheck((int)vObject.InvokeMethodByRef("nSetKeyValue", divObject), "SetDivision");

    successCheck((int)vObject.InvokeMethodByRef("nSetKeyValue", vendorNumberPass), "SetVendorNumber");

    successCheck((int)vObject.InvokeMethod("nSetKey"), "SetVendorKey"); // used when the key is multi-part

    Hope this helps.
    Elliott