Hello and thank you for reading!
I am trying to create a Bill using SOAP. To specify particular non-stock items, I extended endpoint and included field InventoryID-InventoryID into the BillDetail object. Then I updated WSDL file. Export Bills now works fine. But creation fails, with no info on the field.
Here is the code:
string lcSQL, lcErrMsg, lcStage = "Start";
AcmtIntegrator.AcumaticaWSDL.DefaultSoapClient soapClient = null;
soapClient = new AcmtIntegrator.AcumaticaWSDL.DefaultSoapClient(clsACMT.CreateBinding(clsGlobals.gcAcmtURL),
clsACMT.CreateEndpoint(clsGlobals.gcAcmtURL, clsGlobals.gcAcmtEndPoint, clsGlobals.gcAcmtVersion));
string lcBranch, lcLocationID;
lcBranch = mdlGU.GetSystemOption("ACMTEXTRACT", "CreditMemo", "Branch", "YOGIFON");
lcLocationID = mdlGU.GetSystemOption("ACMTEXTRACT", "CreditMemo", "LocationID", "");
// Bill Level:
lcBranch = "SOFT";
string docType = "Bill";
string lcVendorCd = "EP00000001";
string lcVendorRef = "VendorRef - 2";
decimal lnBillAmt = 1000;
string lcDocTxnDate = "20201005", lcDocDueDate = "20201104";
string lcCashAccount = "102000SOFT";
string lcBillDesc = "bill Desc 2";
string lcRefNo = "RefNo";
string lcTerms = "30D";
string lcPostPeriod = "102020";
int lnLineCount = 0;
lcSQL = "select count(*) from tblCBInputCMItemLine where CMHdrID = " + Convert.ToString(1);
lnLineCount = mdlGU.GetSQLScalar(lcSQL, 0);
lnLineCount = 1;
// Bill Line
decimal lnLineExtAmt = 1000, lnUnitCost = 0, lnLineQty = 0;
string lcLinePOOrderNbr = "", lcLinePOOrderType = "", lcLineDesc = "Line Desc", lcLineTranDesc = "Tran Desc";
string lcLineAccount, lcLineSubAccount, lcUoM, lcLineItemInvID, lcLineProject = "", lcLineProjectTask = "";
string lcItemAcmtGuid = "61594ca1-0d6b-e411-a445-e06995c86014";
//
BillDetail[] loBillDetails;
loBillDetails = new BillDetail[lnLineCount];
lcSQL = "select AcmtInventoryID from stdAcmtNonStockItem where AcmtGuid = '" + Convert.ToString(lcItemAcmtGuid) + "'";
lcLineItemInvID = mdlGU.GetSQLScalar(lcSQL, "");
lcSQL = "select ItemDesc from stdAcmtNonStockItem where AcmtGuid = '" + lcItemAcmtGuid + "'";
lcLineDesc = mdlGU.GetSQLScalar(lcSQL, "");
lcSQL = "select ExpenseAccount from stdAcmtNonStockItem where AcmtGuid = '" + lcItemAcmtGuid + "'";
lcLineAccount = mdlGU.GetSQLScalar(lcSQL, "215000");
lcSQL = "select ExpenseSubAccount from stdAcmtNonStockItem where AcmtGuid = '" + lcItemAcmtGuid + "'";
lcLineSubAccount = mdlGU.GetSQLScalar(lcSQL, "");
lcSQL = "select BaseUnit from stdAcmtNonStockItem where AcmtGuid = '" + lcItemAcmtGuid + "'";
lcUoM = mdlGU.GetSQLScalar(lcSQL, "");
loBillDetails[0] = new BillDetail
{
Branch = new StringValue { Value = lcBranch },
Amount = new DecimalValue { Value = lnLineExtAmt },
ExtendedCost = new DecimalValue { Value = lnLineExtAmt },
UnitCost = new DecimalValue { Value = lnUnitCost },
Qty = new DecimalValue { Value = lnLineQty },
TransactionDescription = new StringValue { Value = lcLineTranDesc },
Description = new StringValue { Value = lcLineDesc },
POOrderNbr = new StringValue { Value = lcLinePOOrderNbr },
POOrderType = new StringValue { Value = lcLinePOOrderType },
Account = new StringValue { Value = lcLineAccount },
Subaccount = new StringValue { Value = lcLineSubAccount },
// InventoryID = new StringValue { Value = lcLineItemInvID },
UOM = new StringValue { Value = lcUoM },
//Project = new StringValue { Value = lcLineProject },
//ProjectTask = new StringValue { Value = lcLineProjectTask }
};
Bill loBill = new Bill
{
ReturnBehavior = ReturnBehavior.OnlySpecified,
// Type = new StringValue { Value = docType },
// ReferenceNbr = new StringReturn { Value = lcRefNo },
Type = new StringValue (),
ReferenceNbr = new StringReturn (),
Status = new StringReturn(),
Vendor = new StringValue { Value = lcVendorCd },
VendorRef = new StringValue { Value = lcVendorRef },
PostPeriod = new StringValue { Value = lcPostPeriod },
Terms = new StringValue { Value = lcTerms },
Hold = new BooleanValue { Value = false },
Amount = new DecimalValue { Value = lnBillAmt },
Balance = new DecimalValue { Value = lnBillAmt },
CashAccount = new StringValue { Value = lcCashAccount },
Description = new StringValue { Value = lcBillDesc },
ApprovedForPayment = new BooleanValue { Value = true },
BranchID = new StringValue { Value = lcBranch },
Details = loBillDetails,
};
// LocationID is optional
if (lcLocationID != "")
{
loBill.LocationID = new StringValue { Value = lcLocationID };
}
if (lcDocTxnDate != "")
{
loBill.Date = new DateTimeValue
{
Value = new DateTime(Convert.ToInt32(mdlGU.MyLeft(lcDocTxnDate, 4)),
Convert.ToInt32(lcDocTxnDate.Substring(4, 2)),
Convert.ToInt32(lcDocTxnDate.Substring(6, 2)))
};
loBill.DueDate = new DateTimeValue
{
Value = new DateTime(Convert.ToInt32(mdlGU.MyLeft(lcDocDueDate, 4)),
Convert.ToInt32(lcDocDueDate.Substring(4, 2)),
Convert.ToInt32(lcDocDueDate.Substring(6, 2)))
};
};
//Create a Bill
Bill newBill = new Bill();
try
{
newBill = (Bill)soapClient.Put(loBill);
//lcTxnID = newInvoice.ID.ToString();
//lnPaidAmtCurr = newInvoice.Amount.Value.Value * lnAmtMultiplier;
//lcDocRefNumber = newInvoice.ReferenceNbr.Value;
// User to be "and CMNumberCurr = ''" Not sure why.
// lcSQL = String.Format("Update tblCBInputCMHdr set ProcessingStatusID = 5, CMNumberCurr = '{0}', DocRefNumber = '{0}', TxnID = '{2}', PaidAmtCurr = {3} where CMHdrId = {1} and CMNumberCurr = ''", lcRefNumber, lnCMHdrID, lcTxnID, lnPaidAmtCurr);
//lcSQL = String.Format("Update tblCBInputCMHdr set ProcessingStatusID = 5, CMNumberCurr = '{0}', DocRefNumber = '{4}', TxnID = '{2}', PaidAmtCurr = {3} where CMHdrId = {1}", lcRefNumber, lnCMHdrID, lcTxnID, lnPaidAmtCurr, lcDocRefNumber);
//mdlGU.SqlClientExecuteSQL(lcSQL, "MakeCreditMemo", lcSQL, lcErrMsg);
//mdlGU.WriteAppLog("Make CM", "HeaderID = " + Convert.ToString(lnCMHdrID), "Making CM Lines", false);
//mdlGU.WriteAppLog("Make CreditMemo", "HeaderID = " + Convert.ToString(lnCMHdrID), "Set Status in tblCBInputCMHdr", false);
}
catch (Exception ex)
{
lcErrMsg = ex.Message.Replace("'", "").Substring(0, 900);
}
The full error message says: System.ArgumentNullException: Value cannot be null.\nParameter name: model\n at Microsoft.Data.Edm.EdmUtil.CheckArgumentNull[T](T value, String parameterName)\n at Microsoft.Data.Edm.ExtensionMethods.EntityContainers(IEdmModel model)\n at PX.Api.ContractBased.Edm.Helpers.GetEntityType(IEdmModel model, String objectName)\n at PX.Api.ContractBased.Soap.EntityReaderBase.ReadEntity(String expectedEntityType)\n at PX.Api.ContractBased.Soap.EntityReaderBase.ReadEntity(XmlReader reader, String localname, String expectedNamespace, String expectedEntityType)\n at PX.Api.ContractBased.Soap.SoapMessageTransformerBase.BindParameters(XmlReader requestReader, MethodInfo methodInfo, Tuple`2[] parameterInfos)\n at PX.Api.ContractBased.Soap.WebApiSoapController.Post(ISoapSystemContract systemContract, XmlReader requestReader, String serviceNamespace, String internalNamespace, MethodInfo method, Fun" Exception thrown: 'System.ServiceModel.FaultException' in mscorlib.dll
I am working with local version of Acumatica 2019 and training Tenant MyStore. I am logging in as Admin.
Any help will be greatly appreciated.
Regards, Alexander