RevisionID may not be empty inserting purchase order - acumatica

Hi I am creating a process to insert a purchase order but I have hit an error I cant resolve. When I persist my purchase order I get an error RevisionID may not be empty. I am confused and RevisionID does not appear on any of the DAC's POOrder or POLine.
Here is the error
Message: Error #4: 'RevisionID' may not be empty.
Date/Time: 18/06/2015 12:22
Platform:
Browser:
Source: PX.Data
Target Site: Boolean MoveNext()
Stack Trace: at PX.Data.PXDefaultAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)
at PX.Data.PXCache`1.PersistInserted(Object row)
at PX.Objects.CS.SharedRecordAttribute.RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
at PX.Data.PXCache.OnRowPersisting(Object item, PXDBOperation operation)
at PX.Data.PXCache`1.PersistInserted(Object row)
at PX.Data.PXCache`1.Persist(PXDBOperation operation)
at PX.Data.PXGraph.Persist(Type cacheType, PXDBOperation operation)
at PX.Data.PXGraph.Persist()
at PX.Objects.PO.POOrderEntry.Persist()
at PX.Data.PXSave`1.<Handler>d__4.MoveNext()
at PX.Data.PXAction`1.<Press>d__c.MoveNext()
at PX.Data.PXAction`1.<Press>d__c.MoveNext()
at PX.Data.PXAction`1.Press()
at Exosoft.MP.MikePero.Graphs.GeneratePurchaseOrdersProcess.GeneratePurchaseOrders (List`1 sOrderLines) in c:\Projects\Exosoft\Mike Pero Rex Integration\Dev\Main\Source\MP\MikePero\Graphs\Processes\GeneratePurchaseOrdersProcess.cs:line 102
And here my code for creating the purchase order (unfinished)
private static void GeneratePurchaseOrders(List<PX.Objects.SO.SOLineCustom> sOrderLines)
{
try
{
DateTime firstOfMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
DateTime lastOfMonth = firstOfMonth.AddMonths(1).AddSeconds(-1);
foreach (PX.Objects.SO.SOLineCustom soLine in sOrderLines) {
POOrderEntry graph = PXGraph.CreateInstance<POOrderEntry>();
graph.Clear(PXClearOption.ClearAll);
PX.Objects.IN.InventoryItem item = AdvancedMethods.GetInventoryItemByInventoryID(soLine.InventoryID);
PX.Objects.AP.VendorR vendor = AdvancedMethods.GetVendorByID(item.PreferredVendorID);
if (vendor == null) return;
PX.Objects.CR.Location vLocation = AdvancedMethods.GetLocationByLocationID(vendor.DefLocationID);
if (vLocation == null) return;
//Get Existing Current Months Purchase Order
PX.Objects.PO.POOrder pOrder = PXSelect<PX.Objects.PO.POOrder,
Where<PX.Objects.PO.POOrder.vendorID, Equal<Required<PX.Objects.PO.POOrder.vendorID>>,
And<Where<PX.Objects.PO.POOrder.orderDate, Greater<Required<PX.Objects.PO.POOrder.orderDate>>,
And<PX.Objects.PO.POOrder.orderDate, LessEqual<Required<PX.Objects.PO.POOrder.orderDate>>>>>>>.Select(new PXGraph(), item.PreferredVendorID, firstOfMonth, lastOfMonth);
if (pOrder == null)
{
//Add new purchase order
pOrder = new PX.Objects.PO.POOrder();
pOrder.OrderType = PX.Objects.PO.POOrderType.RegularOrder;
pOrder = PXCache<PX.Objects.PO.POOrder>.CreateCopy(graph.Document.Insert(pOrder));
pOrder.VendorID = vendor.ID;
pOrder.VendorLocationID = vendor.DefLocationID;
pOrder.SiteID = soLine.SiteID;
pOrder.OrderDesc = "Generated Purchase Order";
pOrder.OrderDate = lastOfMonth;
pOrder.TermsID = vendor.TermsID;
}
graph.Document.Current = graph.Document.Search<POOrder.orderNbr>(pOrder.OrderNbr, pOrder.OrderType);
graph.vendor.Current = vendor;
graph.location.Current = vLocation;
//Add Line to Purchase Order
PX.Objects.PO.POLine pLine = new PX.Objects.PO.POLine();
pLine.LineType = POLineType.Service;
pLine.OrderType = pOrder.OrderType;
pLine.RequestedDate = soLine.ShipDate;
pLine.VendorID = pOrder.VendorID;
pLine.VendorLocationID = pOrder.VendorLocationID;
pLine.InventoryID = soLine.InventoryID;
pLine.SubItemID = pLine.SubItemID;
pLine.SiteID = soLine.SiteID;
pLine.UOM = soLine.UOM;
pLine.OrderQty = soLine.Qty;
pLine.TranDesc = soLine.TranDesc;
pLine.ProjectID = soLine.ProjectID;
pLine.TaskID = soLine.TaskID;
pLine.UnitCost = soLine.UnitCost;
pLine.CuryUnitCost = soLine.CuryUnitCost;
pLine = graph.Transactions.Insert(pLine);
graph.Save.Press();
}//foreach
}
catch (Exception ex)
{
ErrorHandling.LogError(ex);
throw new PXException(String.Format("An error occurred generating purchase orders: {0}", ex.Message));
}
}
}//GeneratePurchaseOrdersProcess

Ok I forgot to update the purchase order after I changed properties
pOrder = graph.Document.Update(pOrder);

Related

How to create a custom Order Type using customization plug-in (Acumatica)

How to create a custom Order Type using customization plug-in? I used a manual from here. I tried to initialize required filds from exesting order type, but without success. I tried to use Update method on graph as well. Every time I get a common error: Inserting 'Order Type' record raised at least one error. Please review the errors.' and can't see what field the issue is related to. My UpdateDatabase() method:
public override void UpdateDatabase()
{
SOOrderTypeMaint orderTypeGraph = PXGraph.CreateInstance<SOOrderTypeMaint>();
string newOrderTypeName = "SR";
var existingOrderType = orderTypeGraph.soordertype.Search<SOOrderType.orderType>(newOrderTypeName);
if (existingOrderType.Count != 0)
{
WriteLog(string.Format("{0} type already exist", newOrderTypeName));
}
else
{
SOOrderType exempleOrderType = SOOrderType.PK.Find(orderTypeGraph, "SO");
SOOrderTypeOperation exgrid = SOOrderTypeOperation.PK.Find(orderTypeGraph, "SO", "I");
var ourGrid = new SOOrderTypeOperation();
var sROrderType = new SOOrderType();
ourGrid.Operation = exgrid.Operation;
ourGrid.INDocType = exgrid.INDocType;
ourGrid.OrderPlanType = exgrid.OrderPlanType;
ourGrid.ShipmentPlanType = exgrid.ShipmentPlanType;
ourGrid.RequireReasonCode = exgrid.RequireReasonCode;
sROrderType.OrderType = newOrderTypeName;
sROrderType.Descr = "description";
sROrderType.Active = exempleOrderType.Active;
sROrderType.OrderNumberingID = exempleOrderType.OrderNumberingID;
sROrderType.FreightSubID = exempleOrderType.FreightSubID;
sROrderType.DiscountAcctID = exempleOrderType.DiscountAcctID;
sROrderType.DiscountSubID = exempleOrderType.DiscountSubID;
sROrderType.Behavior = exempleOrderType.Behavior;
sROrderType.DefaultOperation = exempleOrderType.DefaultOperation;
sROrderType.ARDocType = exempleOrderType.ARDocType;
sROrderType.AllowQuickProcess = exempleOrderType.AllowQuickProcess;
sROrderType.DiscSubMask = exempleOrderType.DiscSubMask;
sROrderType.CalculateFreight = exempleOrderType.CalculateFreight;
sROrderType.SalesSubMask = exempleOrderType.SalesSubMask;
sROrderType.FreightSubMask = exempleOrderType.FreightSubMask;
sROrderType.FreightAcctID = exempleOrderType.FreightAcctID;
sROrderType.InvoiceNumberingID = exempleOrderType.InvoiceNumberingID;
sROrderType.RequireShipping = exempleOrderType.RequireShipping;
orderTypeGraph.soordertype.Insert(sROrderType);
orderTypeGraph.operations.Insert(ourGrid);
orderTypeGraph.soordertype.Update(sROrderType);
orderTypeGraph.operations.Update(ourGrid);
orderTypeGraph.Save.Press();
WriteLog(string.Format("{0} type has been added", newOrderTypeName));
}
}
Acumatica trace:
8/6/2021 6:27:14 PM Error:
Publishing of a customization project failed with an error CustomizationProjects:TestAssignment2
PX.Data.PXOuterException: Error: Inserting 'Order Type' record raised at least one error. Please review the errors.
at PX.Data.PXUIFieldAttribute.CommandPreparing(PXCache sender, PXCommandPreparingEventArgs e)
at PX.Data.PXCache.OnCommandPreparing(String name, Object row, Object value, PXDBOperation operation, Type table, FieldDescription& description)
at PX.Data.PXCache`1.PersistInserted(Object row, Boolean bypassInterceptor)
at PX.Data.PXCache`1.Persist(PXDBOperation operation)
at PX.Data.PXGraph.Persist(Type cacheType, PXDBOperation operation)
at PX.Data.PXGraph.Persist()
at PX.Data.PXSave`1.d__2.MoveNext()
at PX.Data.PXAction`1.d__33.MoveNext()
at PX.Data.PXAction`1.d__33.MoveNext()
at PX.Data.PXAction`1.PressImpl(Boolean internalCall, Boolean externalCall)
at PX.Data.PXAction`1.Press()
at TestAssignment2.ServiceRepairCreator.UpdateDatabase() in D:\AcumaticaFolder\TestAssignment\App_Data\Projects\TestAssignment2\TestAssignment2\ServiceRepairCreator.cs:line 58
at Customization.CstWebsiteStorage.UpdateDatabaseFromPlugin(CustomizationPlugin plugin, PXPublishOptions options)
at Customization.CstWebsiteStorage.RunPluginsDbUpdate()
at PX.Web.Customization.Controls.Publish.RunPlugins(HttpResponse response)
The problem was in mandatory fields. This method works when u need to create a new order type. Thanks, everyone, for your help.
public override void UpdateDatabase()
{
SOOrderTypeMaint graph = PXGraph.CreateInstance<SOOrderTypeMaint>();
string newOrderTypeName = Constants.serviceRepairOrderType;
var existingOrderType = graph.soordertype.Search<SOOrderType.orderType>(newOrderTypeName);
if (existingOrderType.Count != 0)
{
WriteLog(string.Format("{0} type already exist", newOrderTypeName));
}
else
{
SOOrderType exempleOrderType = SOOrderType.PK.Find(graph, SOOrderTypeConstants.SalesOrder);
var soSRTypeGeneral = graph.soordertype.Insert();
soSRTypeGeneral.OrderType = newOrderTypeName;
soSRTypeGeneral.Descr = "description";
soSRTypeGeneral.Template = exempleOrderType.Template;
soSRTypeGeneral.Behavior = exempleOrderType.Behavior;
soSRTypeGeneral.ARDocType = exempleOrderType.ARDocType;
soSRTypeGeneral.INDocType = exempleOrderType.INDocType;
soSRTypeGeneral.FreightSubID = exempleOrderType.FreightSubID;
soSRTypeGeneral.OrderPlanType = exempleOrderType.OrderPlanType;
soSRTypeGeneral.DiscountSubID = exempleOrderType.DiscountSubID;
soSRTypeGeneral.FreightAcctID = exempleOrderType.FreightAcctID;
soSRTypeGeneral.DiscountAcctID = exempleOrderType.DiscountAcctID;
soSRTypeGeneral.ShipmentPlanType = exempleOrderType.ShipmentPlanType;
soSRTypeGeneral.OrderNumberingID = exempleOrderType.OrderNumberingID;
soSRTypeGeneral.DefaultOperation = exempleOrderType.DefaultOperation;
soSRTypeGeneral.DaysToKeep = exempleOrderType.DaysToKeep;
soSRTypeGeneral.COGSSubMask = exempleOrderType.COGSSubMask;
soSRTypeGeneral.DiscSubMask = exempleOrderType.DiscSubMask;
soSRTypeGeneral.OrderPriority = exempleOrderType.OrderPriority;
soSRTypeGeneral.FreightSubMask = exempleOrderType.FreightSubMask;
soSRTypeGeneral.RequireShipping = exempleOrderType.RequireShipping;
soSRTypeGeneral.DiscAcctDefault = exempleOrderType.DiscAcctDefault;
soSRTypeGeneral.COGSAcctDefault = exempleOrderType.COGSAcctDefault;
soSRTypeGeneral.SupportsApproval = exempleOrderType.SupportsApproval;
soSRTypeGeneral.AllowQuickProcess = exempleOrderType.AllowQuickProcess;
soSRTypeGeneral.FreightAcctDefault = exempleOrderType.FreightAcctDefault;
var soSRTypeTemplate = graph.operations.Insert();
soSRTypeTemplate.OrderType = soSRTypeGeneral.OrderType;
soSRTypeTemplate.Active = true;
soSRTypeTemplate.InvtMult = -1;
soSRTypeTemplate.Operation = "I";
soSRTypeTemplate.INDocType = "INV";
soSRTypeTemplate.OrderPlanType = "60";
soSRTypeTemplate.ShipmentPlanType = "61";
var soSRTypeQuickParam = graph.quickProcessPreset.Insert();
soSRTypeQuickParam.OrderType = soSRTypeGeneral.OrderType;
soSRTypeQuickParam.UpdateIN = true;
soSRTypeQuickParam.CreateShipment = true;
soSRTypeQuickParam.PrepareInvoice = true;
soSRTypeQuickParam.ConfirmShipment = true;
graph.Persist();
WriteLog(string.Format("{0} type has been added", newOrderTypeName));
}
}

Error While creating Sales Order from Sales Quote (CR304500)

I have created a Action called "CREATE SO" in Sales Quote(CR304500) screen to create Sales Order. I have created a ComboBox udf "Sales Order Type" to select "Doc Type" of the Sales Order to be created.
When I am selecting DocType as "SO", its giving error "Unit
Conversion is missing". (see pic)
When I am selecting any other DocType it gives an error "RevisionID
cannot be empty".(see pic)
"SO" is the default Order Type in SO Preferences. I am unable to track the error using debugger. Please suggest. Thanks. Following is my code.
#region Create Sales Order
public PXAction<CRQuote> createSalesOrder;
[PXUIField(DisplayName = "Create SO", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton(CommitChanges = true)]
public IEnumerable CreateSalesOrder(PXAdapter adapter)
{
QuoteMaint graphObject = PXGraph.CreateInstance<QuoteMaint>();
foreach (CRQuote quote in adapter.Get())
{
//Create resultset for Quote Details
PXResultset<CROpportunityProducts> PXSetLine = PXSelect<CROpportunityProducts,
Where<CROpportunityProducts.quoteID,
Equal<Required<CROpportunityProducts.quoteID>>>>.Select(this.Base, quote.QuoteID);
List<CROpportunityProducts> QuoteList = new List<CROpportunityProducts>();
foreach (CROpportunityProducts line in PXSetLine)
{
QuoteList.Add(line);
}
bool var_orderCreated = false;
bool erroroccured = false;
string ErrMsg = "";
SOOrderEntry orderGraphObjet = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder orderHeaderObject = new SOOrder();
QuoteMaint currGRPH = PXGraph.CreateInstance<QuoteMaint>();
CRQuoteExt _quoteExt = PXCache<CRQuote>.GetExtension<CRQuoteExt>(quote);
var Extension = this.Base.GetExtension<QuoteMaint_Extension>();
orderHeaderObject = orderGraphObjet.CurrentDocument.Insert(orderHeaderObject);
BAccount customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<CRQuote.bAccountID>>>>.Select(this.Base, quote.BAccountID);
if (customer.Type == "CU")
{
orderHeaderObject.CustomerID = quote.BAccountID;
orderHeaderObject.CustomerLocationID = quote.LocationID;
}
else
{
throw new PXException("Business Account not converted to Customer yet");
}
if (quote.CuryProductsAmount != 0)
{
orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
}
else
{
throw new PXException("Total cannot be 0");
}
orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
orderHeaderObject.CuryTaxTotal = quote.CuryTaxTotal;
orderHeaderObject.OrderDesc = quote.Subject;
orderHeaderObject.OrderType = _quoteExt.UsrOrderNbr;
orderGraphObjet.Document.Update(orderHeaderObject);
orderGraphObjet.CurrentDocument.Current = orderHeaderObject;
orderGraphObjet.Actions.PressSave();
orderHeaderObject = orderGraphObjet.CurrentDocument.Current;
foreach (CROpportunityProducts tran in QuoteList)
{
SOLine transline = new SOLine();
orderGraphObjet.Transactions.Insert(transline);
transline.OrderNbr = orderHeaderObject.OrderNbr;
transline.BranchID = orderHeaderObject.BranchID;
transline.InventoryID = tran.InventoryID;
transline.TranDesc = tran.Descr;
transline.UOM = tran.UOM;
transline.OrderQty = tran.Quantity;
transline.SiteID = tran.SiteID;
transline.CuryUnitPrice = tran.CuryUnitPrice;
transline.CuryExtPrice = tran.CuryExtPrice;
transline.CuryLineAmt = tran.CuryAmount;
CROpportunityProductsExt xOppProductExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExt>(tran);
SOLineExt _soLext = PXCache<SOLine>.GetExtension<SOLineExt>(transline);
_soLext.UsrXSeqID = xOppProductExt.UsrXSequenceID;
_soLext.UsrXGroupID = xOppProductExt.UsrXGroupID;
_soLext.UsrInternalRemk = xOppProductExt.UsrInternalRemk;
orderGraphObjet.Transactions.Update(transline);
}
orderGraphObjet.Actions.PressSave(); //This is the line where both the error is showing
if (orderGraphObjet != null && orderHeaderObject != null)
{
orderGraphObjet.Document.Current = orderHeaderObject;
throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
yield return quote;
}
}
############## DAC FIELD #####################
[PXDBString(50)]
[PXUIField(DisplayName = "Sales Order Type")]
[PXDefault()]
[PXStringList(new string[] { "SO", "SP", "SS" }, new string[] { "SO - Sales Order", "SP - Sales Of Project", "SS - Sales Of Service" })]
public virtual string UsrOrderNbr { get; set; }
public abstract class usrOrderNbr : PX.Data.BQL.BqlString.Field<usrOrderNbr> { }
I would suggest that when you insert your new objects into the cache, that you insert an object with it's key elements already entered. For instance, I would add CustomerID and CustomerLocationID to orderHeaderObject and then Insert it into the Document cache. When you do that, the Acumatica validation will fire and all the defaults will be set in your document before you try and edit them. Same goes for your line level object, I think that's the reason you're getting both errors. Also, I notice you trying to set the value for a few calculated fields. If possible I would try and leave these to calculate as designed.

Process multiple invoices and show them all in a single report like How Print Invoices/memos report is working in Acumatica

Basically i want to create a new action button On Print Invoice and Memos screen to print a report for selected invoices.
Why we are creating new action button is, here we need to print different formats for each invoice (SO type) so when user selects 3 different records in grid
for an example
1. INV1234 and so type is TS then i need to print xyz report
2. INV9875 and this has not created through SO then i need to print ABC report
3. CRM4567 and SO type is TS (like above 1 option)
so here 1 & 3 should print in one page (Like same how process button is working in default acumatica)
2 option report should print in new tab.
If i get a sample code on to print same report in single page and other one in another tab is fine.
Below is the code
public PXAction<PrintInvoicesFilter> PrintReport;
[PXUIField(DisplayName = "Print Sales Invoice with Price", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXLookupButton]
public virtual IEnumerable printReport(PXAdapter adapter, [PXString] string reportID)
{
PXReportRequiredException ex = null;
foreach (ARInvoice doc in Base.ARDocumentList.Cache.Cached)
{
var parameters = new Dictionary<string, string>();
if (doc.Selected == true)
{
ARTran TranData = PXSelectReadonly<ARTran, Where<ARTran.tranType, Equal<Required<ARTran.tranType>>,
And<ARTran.refNbr, Equal<Required<ARTran.refNbr>>>>>.Select(Base, doc.DocType, doc.RefNbr);
if (TranData != null)
{
if (TranData.SOOrderType == "WS" || TranData.SOOrderType == "WO" || TranData.SOOrderType == "TS" || TranData.SOOrderType == "IM")
{
if (reportID == null) reportID = "KR501011";
if (reportID == "KR501011")
{
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
}
ex = PXReportRequiredException.CombineReport(ex, "KR501011", parameters,false);
}
if (TranData.SOOrderType == "RX")
{
if (reportID == null) reportID = "KR501016";
if (reportID == "KR501016")
{
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
}
ex = PXReportRequiredException.CombineReport(ex, "KR501016", parameters,false);
}
if (string.IsNullOrEmpty(TranData.SOOrderType))
{
if (reportID == null) reportID = "KR501038";
if (reportID == "KR501038")
{
parameters["DocType"] = doc.DocType;
parameters["RefNbr"] = doc.RefNbr;
}
ex = PXReportRequiredException.CombineReport(ex, "KR501038", parameters,false);
}
}
}
}
if (ex != null)
{
ex.Mode = PXBaseRedirectException.WindowMode.New;
ex.SeparateWindows = false;
throw ex;
}
Thanks in advance.
Redirecting to multiple report or combining multiple report in a single document can only be achieved with method PXReportRequiredException.CombineReport.
The redirection exception has two options to control how the reports are combined:
Print all report as a single PDF file – ex.SeparateWindows = false;
Open each separate report in a new tab – ex.SeparateWindows = true;
Your requirement asked for 1 and 2 at the same time which is not possible. You can only choose option 1 or 2. To get both you would need two actions button to launch the reports.
The reason for the limitation is because to redirect to a report you have to throw an exception. Once the exception is thrown you can't execute code anymore to launch a new report. It is possible to print multiple reports with a single exception as explained below but you have to choose between all reports in same tab (same document) or one report per tab (one document per report).
Blog Source: https://asiablog.acumatica.com/2017/03/launch-multiple-reports-with-one-exception.html
Code example from that blog source:
PXReportRequiredException ex = null;
if(row.ARRefNumber != null)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary["DocType"] = row.ARDocType;
dictionary["RefNbr"] = row.ARRefNumber;
ex = PXReportRequiredException.CombineReport(ex, row.ARBatchNumber == null ? "AR610500" : "AR622000", dictionary, false);
}
if (row.APRefNumber != null)
{
APInvoice inv = PXSelectorAttribute.Select<DocHeader.aPRefNumber>(Document.Cache, row) as APInvoice;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary["DocType"] = row.APDocType;
dictionary["RefNbr"] = row.APRefNumber;
dictionary["PeriodTo"] = PX.Objects.GL.OpenPeriodAttribute.FormatForDisplay(inv.FinPeriodID);
dictionary["PeriodFrom"] = PX.Objects.GL.OpenPeriodAttribute.FormatForDisplay(inv.FinPeriodID);
ex = PXReportRequiredException.CombineReport(ex, row.APBatchNumber == null ? "AP610500" : "AP622000", dictionary, false);
}
if (ex != null)
{
ex.Mode = PXBaseRedirectException.WindowMode.New;
ex.SeparateWindows = true;
throw ex;
}

Shipment Confirmation and Update IN through code is not working

I have a requirement to create shipment document, shipment confirmation and update In on a Sales order Transfer document.
The following code is used for shipment confirmation
public string CreateShipment()
{
bool flag = false;
string _retval = string.Empty;
using (IEnumerator<PXResult<SOOrderShipment>> enumerator = Base.shipmentlist.Select(Array.Empty<object>()).GetEnumerator())
{
if (enumerator.MoveNext())
{
SOOrderShipment current = enumerator.Current;
flag = true;
}
}
if (flag)
{
string Mess = "Error: Shipment already created.";
throw new PXException(Mess);
}
SOShipmentEntry sOShipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
//SOOrderEntry sOOrderEntry = PXGraph.CreateInstance<SOOrderEntry>();
//sOOrderEntry.Caches.Clear();
SOOrder sOOrder = Base.Document.Current;
int? nullable = new int?(0);
int? customerLocationID = new int?(0);
if (sOOrder != null)
{
nullable = sOOrder.CustomerID;
customerLocationID = sOOrder.CustomerLocationID;
}
int? siteID = new int?(0);
//SOShipmentEntry sOShipmentEntry1 = PXGraph.CreateInstance<SOShipmentEntry>();
SOShipment destinationDocument = sOShipmentEntry.Document.Insert();
destinationDocument.ShipmentType = "T";
destinationDocument = sOShipmentEntry.Document.Update(destinationDocument);
destinationDocument.Operation = "I";
destinationDocument = sOShipmentEntry.Document.Update(destinationDocument);
using (IEnumerator<PXResult<SOLine>> enumerator1 = PXSelectReadonly<SOLine, Where<SOLine.orderType, Equal<Required<SOLine.orderType>>, And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>>.Select(Base, new object[] { Base.Document.Current.OrderType, Base.Document.Current.OrderNbr }).GetEnumerator())
{
if (enumerator1.MoveNext())
{
SOLine line = (SOLine)enumerator1.Current;
siteID = line.SiteID;
}
}
destinationDocument.SiteID = siteID;
destinationDocument.DestinationSiteID = sOOrder.DestinationSiteID;
destinationDocument = sOShipmentEntry.Document.Update(destinationDocument);
//sOOrderEntry.Document.Current = sOOrder;
if (Base.Document.Current != null)
{
DocumentList<SOShipment> documentList = new DocumentList<SOShipment>(sOShipmentEntry);
sOShipmentEntry.CreateShipment(Base.Document.Current, sOShipmentEntry.Document.Current.SiteID, sOShipmentEntry.Document.Current.ShipDate, new bool?(false), "I", documentList);
if (sOShipmentEntry.Document.Current.ShipmentNbr != null)
{
SOOrderEntry sOOrderEntry1 = PXGraph.CreateInstance<SOOrderEntry>();
sOOrderEntry1.Clear();
sOOrderEntry1.Document.Current = sOOrder;
int? openShipmentCntr = Base.Document.Current.OpenShipmentCntr;
if ((openShipmentCntr.GetValueOrDefault() > 0 ? openShipmentCntr.HasValue : false))
{
sOOrder.Status = SOOrderStatus.Shipping;
sOOrder.Hold = new bool?(false);
sOOrderEntry1.Document.Update(sOOrder);
sOOrderEntry1.Save.Press();
_retval = sOShipmentEntry.Document.Current.ShipmentNbr;
}
}
}
return _retval;
}
The following code confirms the shipment and update IN.
private void ConfirmShipment(string shipmentnbr)
{
SOShipmentEntry sOShipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
SOOrderEntry sOOrderEntry = PXGraph.CreateInstance<SOOrderEntry>();
sOShipmentEntry.Clear();
sOOrderEntry.Clear();
sOOrderEntry.Document.Current = PXSelect<SOOrder, Where<SOOrder.orderType, Equal<Required<SOOrder.orderType>>, And<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>>.Select(sOOrderEntry, Base.Document.Current.OrderType, Base.Document.Current.OrderNbr);
sOShipmentEntry.Document.Current = PXSelect<SOShipment,Where<SOShipment.shipmentNbr, Equal<Required<SOShipment.shipmentNbr>>>>.Select(sOShipmentEntry,shipmentnbr);
if(sOShipmentEntry.Document.Current!= null && sOOrderEntry.Document.Current != null)
{
sOShipmentEntry.ConfirmShipment(sOOrderEntry, sOShipmentEntry.Document.Current);
sOShipmentEntry.UpdateIN.Press();
}
}
I am able to select sales order in purchase receipt transfer document, but the shipment document status still shows open and not completed.
I have tried the run confirm shipment on the document which is already confirmed through code from the menu of shipment document and I am getting the following error
“Shipment counters are corrupted.”

Create sales order via code 2017 R2

I am trying to create sales orders with data retrieved from my edi system. I have the code working to retrieve the orders, but I am having trouble creating the SO. I can create them with an external program using the SOAP interface, but I am trying to use the graph and insert them directly. I get an exception stating "{"Error: An error occurred during processing of the field CustomerLocationID : Object reference not set to an instance of an object.."}" but I successfully looked up the customer id and location id. Here is the code for my routine. I use similar code to create records for a new master/detail set of tables that I created.
Please advise if anyone has insight on creating sales orders in this manner. The error is thrown at the line:
soOrder.CurrentDocument.Insert(order);
I also am getting an error trying to access the extended fields for SOOrder and SOLine. I currently commented those fields out to see if I could create an order, but I will need to load data in them as well.
foreach (LingoOrderSearch ediOrder in doc850)
{
res850 = lingo.Retrieve850(ediOrder.documentId, "850");
SOOrderEntry soOrder = PXGraph.CreateInstance<SOOrderEntry>();
soOrder.Clear();
var order = new SOOrder();
//SOOrderExt orderExt = order.GetExtension<SOOrderExt>();
order.OrderType = "SO";
order.Status = "Open";
if (res850.Data850.partner == "BEDBATH" || res850.Data850.partner == "BEDBATH_CAN")
customerLookup = "BBB";
else
customerLookup = res850.Data850.partner;
CustomerMaint customerGraph = PXGraph.CreateInstance<CustomerMaint>();
Customer arCustomer = PXSelect<Customer, Where<Customer.status, Equal<Required<Customer.status>>,
And<Customer.acctCD, Equal<Required<Customer.acctCD>>>>>.Select(this, "Active", customerLookup);
if (arCustomer == null)
throw new PXException("Unable to find customer " + customerLookup + " (partner:" + res850.Data850.partner + ")");
order.CustomerID = arCustomer.BAccountID;
CustomerLocationMaint customerLocationGraph = PXGraph.CreateInstance<CustomerLocationMaint>();
Location arCustomerLocation = PXSelect<Location, Where<Location.isActive, Equal<Required<Location.isActive>>,
And<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>>
.Select(this, true, arCustomer.BAccountID, res850.Data850.location);
if (arCustomerLocation == null)
throw new PXException("Unable to find customer location" + customerLookup + " / " +
res850.Data850.location + " (partner:" + res850.Data850.partner + ")");
order.CustomerLocationID = arCustomerLocation.LocationID;
order.CustomerOrderNbr = res850.Data850.poNumber;
order.ExtRefNbr = res850.Data850.documentId.ToString();
//orderExt.UsrEDICustomerVendorId = res850.Data850.vendor;
//orderExt.UsrEDICustomerId = res850.Data850.partner;
if (!DateTime.TryParse(res850.Data850.poDate, out tempDate))
{
tempDate = DateTime.Today;
}
order.DocDate = tempDate;
DateTime.TryParse(res850.Data850.requestedDeliveryDate, out tempDate);
if (!DateTime.TryParse(res850.Data850.requestedDeliveryDate, out tempDate))
{
tempDate = DateTime.Today;
}
order.RequestDate = tempDate;
soOrder.CurrentDocument.Insert(order);
soOrder.Persist();
newOrderId = soOrder.CurrentDocument.Current.OrderNbr;
itemList = res850.Data850.items;
foreach (EdiDoc850Lingoitems item in itemList)
{
InventoryItemMaint invItemGraph = PXGraph.CreateInstance<InventoryItemMaint>();
InventoryItem invItem = PXSelect<InventoryItem,
Where<InventoryItem.itemStatus, Equal<Required<InventoryItem.itemStatus>>,
And<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>>
.Select(this, "Active", item.vendorItem);
if (invItem == null)
throw new PXException("Unable to locate item " + item.vendorItem);
var line = new SOLine();
//SOLineExt lineExt = line.GetExtension<SOLineExt>();
line.OrderNbr = newOrderId;
line.InventoryID = invItem.InventoryID;
line.Qty = item.qtyOrder;
line.ShipComplete = "Ship Complete";
Int32 tempLine = 0;
if (Int32.TryParse(item.lineNo, out tempLine)) { };
//lineExt.UsrEDILineNbr = tempLine;
soOrder.Transactions.Insert(line);
}
}
}
Hopefully, the sample below will help move forward with your task:
SOOrderEntry soOrder = PXGraph.CreateInstance<SOOrderEntry>();
var order = new SOOrder();
order.OrderType = SOOrderTypeConstants.SalesOrder;
order = soOrder.CurrentDocument.Insert(order);
Customer arCustomer = PXSelect<Customer, Where<Customer.status, Equal<Required<Customer.status>>,
And<Customer.acctCD, Equal<Required<Customer.acctCD>>>>>.Select(this, "Active", "ABARTENDE");
if (arCustomer == null)
throw new PXException("Unable to find customer");
order.CustomerID = arCustomer.BAccountID;
order = soOrder.CurrentDocument.Update(order);
Location arCustomerLocation = PXSelect<Location, Where<Location.isActive, Equal<Required<Location.isActive>>,
And<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>>
.Select(this, true, arCustomer.BAccountID, "CHICAGO");
if (arCustomerLocation == null)
throw new PXException("Unable to find customer location");
order.CustomerLocationID = arCustomerLocation.LocationID;
order.CustomerOrderNbr = "res850.Data850.poNumber";
order.ExtRefNbr = "res850.Data850.documentId";
order.RequestDate = DateTime.Today;
soOrder.CurrentDocument.Update(order);
for(int i = 0; i < 3; i++)
{
InventoryItem invItem = PXSelect<InventoryItem,
Where<InventoryItem.itemStatus, Equal<Required<InventoryItem.itemStatus>>,
And<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>>
.Select(this, "Active", "AALEGO500");
if (invItem == null)
throw new PXException("Unable to locate item");
var line = soOrder.Transactions.Insert();
line.InventoryID = invItem.InventoryID;
line.Qty = 1;
line.ShipComplete = SOShipComplete.ShipComplete;
soOrder.Transactions.Update(line);
}
soOrder.Actions.PressSave();

Resources