Hi All,
This is an extension from one of my last issues: How to Delete a Release Using a Custom Action
This is a very complicated BPM for me, so let me break it down.
The underlying updatable BAQ returns a list of order releases from my user defined table (UD02). Most of the releases in this table match to open releases in our Epicor system. But some of them do not. This query returns a list of orders that are not in our system.
The idea is that you can review the list of releases not in our system, then click a checkbox to add that release to our system. The query tries to find a related order and line number based on the available information.(Part, PO, XRef, etc.) Depending on what is available, the query may have to do one of a few things.
Add a release to a closed order on a new line.
Add a release to a closed order on a closed line.
Add a release to an open order on a closed line.
Add a release to an open order on an open line.
Add a release to an open order on a new line.
So working from the top of the action down through the flowchart:
- First, I check the actionID to make sure I process the right action. There is a second action I haven’t even gotten into yet.
- Next, we set myrow and totalrows to 1.
- Next, we “Pull In Data” using the first custom code element:
PullInData
var ttResults_xRow = (from ttResults_Row in ttResults where ttResults_Row.Calculated_NewRelease == true select ttResults_Row).First();
if (ttResults_xRow != null)
{
IsNewLine=false;
totalrows = ttResults.Count / 2; //not sure why this is divided by 2, but it works...
if (myrow <= totalrows)
{
MyOrder = ttResults_xRow.OrderHed2_OrderNum;
if (String.IsNullOrEmpty(Convert.ToString(ttResults_xRow.OrderDtl1_OrderLine)))
{
MyLine = 0;
}
else
{
MyLine = ttResults_xRow.OrderDtl1_OrderLine;
}
MyQty = ttResults_xRow.UD02_Number01;
MyDate = ttResults_xRow.UD02_Date01;
MyPart = ttResults_xRow.UD02_ShortChar01;
ttResults_xRow.Calculated_NewRelease = false;
}
}
- Next, we look to see if the order is closed, if so we reopen it.
- Next, if myline=0 it basically means that we have to add a new line. Otherwise we add a new release to the suggested line (returned from the query).
- Next, to create a new line we run the GetNewOrderDtl method.
- Then, we update the relevant line information and update the entire order with the Update method.
- Next we process the “Set myline” custom code element:
SetMyLine
var OrderDtl = (from row in Db.OrderDtl where row.Company == Session.CompanyID && row.OrderNum == MyOrder orderby row.OrderLine descending select row).FirstOrDefault();
{
MyLine = OrderDtl.OrderLine;
}
IsNewLine=true;
- Now we are looping back into the check to see if myline=0. If we just created a line then we have a line number now so we can just add a new release.
- Next, we add a new release using the GetNewOrderRel method.
- Then, we update the required fields, and then update the entire order with the Update method.
- Now we process the “Delete First Rel” custom code. I only have to do this because I can’t figure out how to update the first release that gets created with a new line. So I update the new release I just added, then delete the first empty release.
DeleteFirstRel
using (Erp.Contracts.SalesOrderSvcContract soSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
{
if (IsNewLine = true)
{
SalesOrderTableset SOTS = soSvc.GetByID(MyOrder);
var desiredReleases = SOTS.OrderRel.Where(r => r.OrderLine == MyLine && r.OrderRelNum == 1);
foreach(var rel in desiredReleases)
{
rel.RowMod = "D";
}
soSvc.Update(ref SOTS);
}
}
- Next, we update the order with the Update method.
- Next, we set myrow=myrow+1
- Then, we check to see if we have reached the end of myrows. If not we continue back to the “Pull In Data” custom code element to process the next record. If we are at the end, then just tell the user.
The code works well when I only check one new release for an open order on an open line. However, when I try to add two releases to a closed order on a new line, I get the error below. I tried to run a trace, but it didn’t tell me anything extra. How do I tell what line of code this error is referencing? I went through each of my custom code elements and added junk code to see if I could get the line number to change, maybe to help point me towards the right section, but no matter what I added or removed the line is always 73 and column is 17.
Business Layer Exception
The table queryResultDataset.Results has more than one record
Exception caught in: Epicor.ServiceModel
Error Detail
Description: The table queryResultDataset.Results has more than one record
Program: Epicor.Customization.BPM.dll
Method: GetSingleRow
> Line Number: 73
> Column Number: 17
Table: queryResultDataset.ResultsClient Stack Trace
at Epicor.ServiceModel.Channels.ImplBase
1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets) at Ice.Proxy.BO.DynamicQueryImpl.RunCustomAction(DynamicQueryDataSet queryDS, String actionID, DataSet queryResultDataset) at Ice.Adapters.DynamicQueryAdapter.<>c__DisplayClass33_0.<RunCustomAction>b__0(DataSet datasetToSend) at Ice.Adapters.DynamicQueryAdapter.ProcessUbaqMethod(String methodName, DataSet updatedDS, Func
2 methodExecutor, Boolean refreshQueryResultsDataset)
at Ice.Adapters.DynamicQueryAdapter.RunCustomAction(DynamicQueryDataSet queryDS, String actionId, DataSet updatedDS, Boolean refreshQueryResultsDataset)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.<>c__DisplayClass384_0.b__0(Int32& rowReturned)
at Ice.UI.App.BAQDesignerEntry.Forms.BAQDiagramForm.ShowQueryResults(DataSet dsResults, getQueryResult getResults, ReportAdditionalInfo additionalInfo)
at Ice.UI.App.BAQDesignerEntry.BAQTransaction.CallRunCustom()
Here is the flowchart image of my BPM.