EDIT FROM THE FUTURE
Solution is post 3, as indicated.
In post 14, We figured out my problem with widgets, and that is that I have UD fields on the
ReqHeadtable (actually just one,Plant_c), and the Fill Table by Query widget is not equipped for that.And now, the original post.
I need help. I promise I have tried all I can think of already. Yes, I am doing this with widgets, but I will take (working) code at this point. I’ve seen snippets, but no one was yet kind enough to share the whole shebang. (I will likely try to reverse-engineer it and widgetize it. Or use as-is.)
For the uninitiated, there is no DispatchReq method of the Req BO. I wish.
Instead, a second row is magically added to the ReqHead table of the dataset, and certain fields are populated/changed. Then call the Update method.
The main existing post on this is here, and below I have pasted the likely solution in its entirety:
Yeah, it wants 2 lines in your dataset before the update: the initial one without any changes and RowMod=“” and the second one with the changes and RowMod=“U”.
First, call the GetByID to get the full req dataset (in this case tsReq). Then copy the header and set the fields:
// copy header var currentRow = tsReq.ReqHead[0]; var newRow = tsReq.ReqHead.NewRow(); BufferCopy.CopyExceptFor(currentRow, newRow, ""); // set fields for the new header newRow["NextDispatcherID"] = "ApproverIDHere"; newRow["NextActionID"] = "APPR"; newRow["ReplyOption"] = "A"; newRow["ReqUserId"] = "RequestorIDHere"; newRow["RowMod"] = "U"; // add new header to tableset tsReq.ReqHead.Add(newRow);Finally, call the Update. Worked for me.
To give context, here is what I see when I compare the two rows of the trace on the Update.
Same fields as the snippet above, but I see more:
- Adding the note (optional, OK fine)
- Adding descriptions (likely not stored in the DB; this is probably purely a UI thing, OK fine)
- Adding an entire new field to the second row!
To explain that, notice that BOTH have ReqUserId but only the right side (added row) has ReqUserID (with capital D; highlighted blue).
This does not correlate to others’ advice; they do not add this field; instead they just populate ReqUserId (lowercase D) on the added row. Is this irrelevant? Seems so, since others report success.
What I have done, with widgets, is:
- Create Epicor Function with several inputs
- Call
GetByIDmethod (ofReqBO) - Use “Fill Table by Query” widget
a. Query the existing (one) row of the dataset
b. Map fields like the pic below - Call
Updatemethod (ofReqBO)
But when I test this, I get a useless error, which correlates to another useless error: Object reference not set to an instance of an object.
I learned out how to dump the auto-generated code, if it helps.
Expand for code
using Epicor.Customization.Bpm;
using Epicor.Data;
using Epicor.Hosting;
using Epicor.Utilities;
using Erp;
using Erp.Tables;
using Ice;
using Ice.Contracts;
using Ice.Customization.Sandbox;
using Ice.ExtendedData;
using Ice.Tables;
using Ice.Tablesets;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
namespace EFx.ReqDCLib.Implementation
{
partial class Dispatch2Impl
{
protected override int RunStep(int workflowStep)
{
var conditionBlockValue = false;
switch (workflowStep)
{
case Epicor.Functions.PredefinedStep.Start: // Req GetByID
using (var widgetContext = this.SetWidgetContext("Req GetByID", "InvokeBOMethodAction2"))
{
try
{
this.A001_InvokeBOMethodAction2();
}
catch (Ice.Common.BusinessObjectException ex)
{
this.RememberException(ex);
}
return 1;
}
case 1: // row count 1
using (var widgetContext = this.SetWidgetContext("row count 1", "SetArgumentAction"))
{
try
{
this.A002_SetArgumentAction();
}
catch (Ice.Common.BusinessObjectException ex)
{
this.RememberException(ex);
}
return 2;
}
case 2: // Add row for update
using (var widgetContext = this.SetWidgetContext("Add row for update", "FillTableByQueryAction"))
{
try
{
this.A003_FillTableByQueryAction();
}
catch (Ice.Common.BusinessObjectException ex)
{
this.RememberException(ex);
}
return 3;
}
case 3: // Update Req
using (var widgetContext = this.SetWidgetContext("Update Req", "InvokeBOMethodAction2"))
{
try
{
this.A004_InvokeBOMethodAction2();
}
catch (Ice.Common.BusinessObjectException ex)
{
this.RememberException(ex);
}
return 4;
}
case 4: // Set Argument/Variable 1
using (var widgetContext = this.SetWidgetContext("Set Argument/Variable 1", "SetArgumentAction"))
{
try
{
this.A005_SetArgumentAction();
}
catch (Ice.Common.BusinessObjectException ex)
{
this.RememberException(ex);
}
return Epicor.Functions.PredefinedStep.Exit;
}
default:
return Epicor.Functions.PredefinedStep.Unknown;
}
}
private void A001_InvokeBOMethodAction2()
{
this.CallService<Erp.Contracts.ReqSvcContract>(
bo =>
{
dsReq = bo.GetByID(
ReqID);
});
}
private void A002_SetArgumentAction()
{
this.output = this.A002_SetArgumentAction_Value();
}
[Epicor.Customization.CustomCode]
private System.String A002_SetArgumentAction_Value()
{
return ("Header rows: " + dsReq.ReqHead.Count.ToString());
}
private class A003_FillTableByQueryAction__QueryRow
{
public System.String dsReq_ReqHead_Company { get; set; }
public System.Boolean dsReq_ReqHead_OpenReq { get; set; }
public System.Int32 dsReq_ReqHead_ReqNum { get; set; }
public System.String dsReq_ReqHead_RequestorID { get; set; }
public System.DateTime? dsReq_ReqHead_RequestDate { get; set; }
public System.String dsReq_ReqHead_ShipName { get; set; }
public System.String dsReq_ReqHead_ShipAddress1 { get; set; }
public System.String dsReq_ReqHead_ShipAddress2 { get; set; }
public System.String dsReq_ReqHead_ShipAddress3 { get; set; }
public System.String dsReq_ReqHead_ShipCity { get; set; }
public System.String dsReq_ReqHead_ShipState { get; set; }
public System.String dsReq_ReqHead_ShipZIP { get; set; }
public System.String dsReq_ReqHead_ShipCountry { get; set; }
public System.Int32 dsReq_ReqHead_PrcConNum { get; set; }
public System.String dsReq_ReqHead_CommentText { get; set; }
public System.String dsReq_ReqHead_ShipToConName { get; set; }
public System.Int32 dsReq_ReqHead_ShipCountryNum { get; set; }
public System.String dsReq_ReqHead_ReqActionID { get; set; }
public System.String dsReq_ReqHead_CurrDispatcherID { get; set; }
public System.Boolean dsReq_ReqHead_NotifyUponReceipt { get; set; }
public System.String dsReq_ReqHead_Note { get; set; }
public System.String dsReq_ReqHead_StatusType { get; set; }
public System.String dsReq_ReqHead_GlbCompany { get; set; }
public System.Int32 dsReq_ReqHead_GlbReqNum { get; set; }
public System.String dsReq_ReqHead_CPDispatcherID { get; set; }
public System.Guid dsReq_ReqHead_SysRowID { get; set; }
public System.String dsReq_ReqHead_CreatedBy { get; set; }
public System.DateTime? dsReq_ReqHead_CreatedOn { get; set; }
public System.String dsReq_ReqHead_AddrList { get; set; }
public System.String dsReq_ReqHead_CurrDispatcherCurMenuID { get; set; }
public System.Boolean dsReq_ReqHead_LockLines { get; set; }
public System.Boolean dsReq_ReqHead_MemoAvailable { get; set; }
public System.String dsReq_ReqHead_NextActionDesc { get; set; }
public System.String dsReq_ReqHead_NextActionID { get; set; }
public System.String dsReq_ReqHead_NextDispatcherID { get; set; }
public System.String dsReq_ReqHead_NextDispatcherName { get; set; }
public System.String dsReq_ReqHead_NextNote { get; set; }
public System.Boolean dsReq_ReqHead_OkToBuy { get; set; }
public System.String dsReq_ReqHead_ReplyOption { get; set; }
public System.String dsReq_ReqHead_RequestorIDCurMenuID { get; set; }
public System.String dsReq_ReqHead_ReqUserId { get; set; }
public System.String dsReq_ReqHead_StatusDesc { get; set; }
public System.Boolean dsReq_ReqHead_ToDoFlag { get; set; }
public System.String dsReq_ReqHead_ShipToAddressFormatted { get; set; }
public System.Int32 dsReq_ReqHead_BitFlag { get; set; }
public System.String dsReq_ReqHead_CurrDispatcherName { get; set; }
public System.String dsReq_ReqHead_ReqActionIDReqActionDesc { get; set; }
public System.String dsReq_ReqHead_RequestorIDName { get; set; }
public System.Boolean dsReq_ReqHead_XbSystDisableOverridePriceListOption { get; set; }
public System.String dsReq_ReqHead_RowMod { get; set; }
public System.String dsReq_ReqHead_Plant_c { get; set; }
public System.Int64 dsReq_ReqHead_SysRevID { get; set; }
}
private void A003_FillTableByQueryAction()
{
var companyDateTimeForCriteria_at_A003_FillTableByQueryAction = Ice.Lib.CompanyTime.Now();
var lazyQueryGen =
from rowdsReq_ReqHead in dsReq.ReqHead
select new A003_FillTableByQueryAction__QueryRow
{
dsReq_ReqHead_Company = rowdsReq_ReqHead.Company,
dsReq_ReqHead_OpenReq = rowdsReq_ReqHead.OpenReq,
dsReq_ReqHead_ReqNum = rowdsReq_ReqHead.ReqNum,
dsReq_ReqHead_RequestorID = rowdsReq_ReqHead.RequestorID,
dsReq_ReqHead_RequestDate = rowdsReq_ReqHead.RequestDate,
dsReq_ReqHead_ShipName = rowdsReq_ReqHead.ShipName,
dsReq_ReqHead_ShipAddress1 = rowdsReq_ReqHead.ShipAddress1,
dsReq_ReqHead_ShipAddress2 = rowdsReq_ReqHead.ShipAddress2,
dsReq_ReqHead_ShipAddress3 = rowdsReq_ReqHead.ShipAddress3,
dsReq_ReqHead_ShipCity = rowdsReq_ReqHead.ShipCity,
dsReq_ReqHead_ShipState = rowdsReq_ReqHead.ShipState,
dsReq_ReqHead_ShipZIP = rowdsReq_ReqHead.ShipZIP,
dsReq_ReqHead_ShipCountry = rowdsReq_ReqHead.ShipCountry,
dsReq_ReqHead_PrcConNum = rowdsReq_ReqHead.PrcConNum,
dsReq_ReqHead_CommentText = rowdsReq_ReqHead.CommentText,
dsReq_ReqHead_ShipToConName = rowdsReq_ReqHead.ShipToConName,
dsReq_ReqHead_ShipCountryNum = rowdsReq_ReqHead.ShipCountryNum,
dsReq_ReqHead_ReqActionID = rowdsReq_ReqHead.ReqActionID,
dsReq_ReqHead_CurrDispatcherID = rowdsReq_ReqHead.CurrDispatcherID,
dsReq_ReqHead_NotifyUponReceipt = rowdsReq_ReqHead.NotifyUponReceipt,
dsReq_ReqHead_Note = rowdsReq_ReqHead.Note,
dsReq_ReqHead_StatusType = rowdsReq_ReqHead.StatusType,
dsReq_ReqHead_GlbCompany = rowdsReq_ReqHead.GlbCompany,
dsReq_ReqHead_GlbReqNum = rowdsReq_ReqHead.GlbReqNum,
dsReq_ReqHead_CPDispatcherID = rowdsReq_ReqHead.CPDispatcherID,
dsReq_ReqHead_SysRowID = rowdsReq_ReqHead.SysRowID,
dsReq_ReqHead_CreatedBy = rowdsReq_ReqHead.CreatedBy,
dsReq_ReqHead_CreatedOn = rowdsReq_ReqHead.CreatedOn,
dsReq_ReqHead_AddrList = rowdsReq_ReqHead.AddrList,
dsReq_ReqHead_CurrDispatcherCurMenuID = rowdsReq_ReqHead.CurrDispatcherCurMenuID,
dsReq_ReqHead_LockLines = rowdsReq_ReqHead.LockLines,
dsReq_ReqHead_MemoAvailable = rowdsReq_ReqHead.MemoAvailable,
dsReq_ReqHead_NextActionDesc = rowdsReq_ReqHead.NextActionDesc,
dsReq_ReqHead_NextActionID = rowdsReq_ReqHead.NextActionID,
dsReq_ReqHead_NextDispatcherID = rowdsReq_ReqHead.NextDispatcherID,
dsReq_ReqHead_NextDispatcherName = rowdsReq_ReqHead.NextDispatcherName,
dsReq_ReqHead_NextNote = rowdsReq_ReqHead.NextNote,
dsReq_ReqHead_OkToBuy = rowdsReq_ReqHead.OkToBuy,
dsReq_ReqHead_ReplyOption = rowdsReq_ReqHead.ReplyOption,
dsReq_ReqHead_RequestorIDCurMenuID = rowdsReq_ReqHead.RequestorIDCurMenuID,
dsReq_ReqHead_ReqUserId = rowdsReq_ReqHead.ReqUserId,
dsReq_ReqHead_StatusDesc = rowdsReq_ReqHead.StatusDesc,
dsReq_ReqHead_ToDoFlag = rowdsReq_ReqHead.ToDoFlag,
dsReq_ReqHead_ShipToAddressFormatted = rowdsReq_ReqHead.ShipToAddressFormatted,
dsReq_ReqHead_BitFlag = rowdsReq_ReqHead.BitFlag,
dsReq_ReqHead_CurrDispatcherName = rowdsReq_ReqHead.CurrDispatcherName,
dsReq_ReqHead_ReqActionIDReqActionDesc = rowdsReq_ReqHead.ReqActionIDReqActionDesc,
dsReq_ReqHead_RequestorIDName = rowdsReq_ReqHead.RequestorIDName,
dsReq_ReqHead_XbSystDisableOverridePriceListOption = rowdsReq_ReqHead.XbSystDisableOverridePriceListOption,
dsReq_ReqHead_RowMod = rowdsReq_ReqHead.RowMod,
dsReq_ReqHead_Plant_c = rowdsReq_ReqHead.UDField<System.String>("Plant_c"),
dsReq_ReqHead_SysRevID = rowdsReq_ReqHead.SysRevID,
};
var queryRowsGen = lazyQueryGen.ToList();
foreach (var queryRow in queryRowsGen)
{
var addedRowGen = new Erp.Tablesets.ReqHeadRow();
addedRowGen.Company = queryRow.dsReq_ReqHead_Company;
addedRowGen.OpenReq = queryRow.dsReq_ReqHead_OpenReq;
addedRowGen.ReqNum = queryRow.dsReq_ReqHead_ReqNum;
addedRowGen.RequestorID = queryRow.dsReq_ReqHead_RequestorID;
addedRowGen.RequestDate = queryRow.dsReq_ReqHead_RequestDate;
addedRowGen.ShipName = queryRow.dsReq_ReqHead_ShipName;
addedRowGen.ShipAddress1 = queryRow.dsReq_ReqHead_ShipAddress1;
addedRowGen.ShipAddress2 = queryRow.dsReq_ReqHead_ShipAddress2;
addedRowGen.ShipAddress3 = queryRow.dsReq_ReqHead_ShipAddress3;
addedRowGen.ShipCity = queryRow.dsReq_ReqHead_ShipCity;
addedRowGen.ShipState = queryRow.dsReq_ReqHead_ShipState;
addedRowGen.ShipZIP = queryRow.dsReq_ReqHead_ShipZIP;
addedRowGen.ShipCountry = queryRow.dsReq_ReqHead_ShipCountry;
addedRowGen.PrcConNum = queryRow.dsReq_ReqHead_PrcConNum;
addedRowGen.CommentText = queryRow.dsReq_ReqHead_CommentText;
addedRowGen.ShipToConName = queryRow.dsReq_ReqHead_ShipToConName;
addedRowGen.ShipCountryNum = queryRow.dsReq_ReqHead_ShipCountryNum;
addedRowGen.ReqActionID = queryRow.dsReq_ReqHead_ReqActionID;
addedRowGen.CurrDispatcherID = queryRow.dsReq_ReqHead_CurrDispatcherID;
addedRowGen.NotifyUponReceipt = queryRow.dsReq_ReqHead_NotifyUponReceipt;
addedRowGen.Note = queryRow.dsReq_ReqHead_Note;
addedRowGen.StatusType = queryRow.dsReq_ReqHead_StatusType;
addedRowGen.GlbCompany = queryRow.dsReq_ReqHead_GlbCompany;
addedRowGen.GlbReqNum = queryRow.dsReq_ReqHead_GlbReqNum;
addedRowGen.CPDispatcherID = queryRow.dsReq_ReqHead_CPDispatcherID;
addedRowGen.SysRevID = queryRow.dsReq_ReqHead_SysRevID;
addedRowGen.SysRowID = queryRow.dsReq_ReqHead_SysRowID;
addedRowGen.CreatedBy = queryRow.dsReq_ReqHead_CreatedBy;
addedRowGen.CreatedOn = queryRow.dsReq_ReqHead_CreatedOn;
addedRowGen.AddrList = queryRow.dsReq_ReqHead_AddrList;
addedRowGen.CurrDispatcherCurMenuID = queryRow.dsReq_ReqHead_CurrDispatcherCurMenuID;
addedRowGen.LockLines = queryRow.dsReq_ReqHead_LockLines;
addedRowGen.MemoAvailable = queryRow.dsReq_ReqHead_MemoAvailable;
addedRowGen.NextActionDesc = queryRow.dsReq_ReqHead_NextActionID;
addedRowGen.NextActionID = ReqAction;
addedRowGen.NextDispatcherID = DispatcherID;
addedRowGen.NextDispatcherName = queryRow.dsReq_ReqHead_NextDispatcherName;
addedRowGen.NextNote = queryRow.dsReq_ReqHead_NextNote;
addedRowGen.OkToBuy = queryRow.dsReq_ReqHead_OkToBuy;
addedRowGen.ReplyOption = Approval;
addedRowGen.RequestorIDCurMenuID = queryRow.dsReq_ReqHead_RequestorIDCurMenuID;
addedRowGen.ReqUserId = UserID;
addedRowGen.StatusDesc = queryRow.dsReq_ReqHead_StatusDesc;
addedRowGen.ToDoFlag = queryRow.dsReq_ReqHead_ToDoFlag;
addedRowGen.ShipToAddressFormatted = queryRow.dsReq_ReqHead_ShipToAddressFormatted;
addedRowGen.BitFlag = queryRow.dsReq_ReqHead_BitFlag;
addedRowGen.CurrDispatcherName = queryRow.dsReq_ReqHead_CurrDispatcherName;
addedRowGen.ReqActionIDReqActionDesc = queryRow.dsReq_ReqHead_ReqActionIDReqActionDesc;
addedRowGen.RequestorIDName = queryRow.dsReq_ReqHead_RequestorIDName;
addedRowGen.XbSystDisableOverridePriceListOption = queryRow.dsReq_ReqHead_XbSystDisableOverridePriceListOption;
addedRowGen.RowMod = A003_FillTableByQueryAction_RowMod(queryRow, addedRowGen);
addedRowGen["Plant_c"] = queryRow.dsReq_ReqHead_Plant_c;
dsReq.ReqHead.Add(addedRowGen);
}
}
[Epicor.Customization.CustomCode]
private System.String A003_FillTableByQueryAction_RowMod(A003_FillTableByQueryAction__QueryRow queryRow, Erp.Tablesets.ReqHeadRow addedRowGen)
{
return ("U");
}
private void A004_InvokeBOMethodAction2()
{
this.CallService<Erp.Contracts.ReqSvcContract>(
bo =>
{
bo.Update(
ref dsReq);
});
}
private void A005_SetArgumentAction()
{
this.output = this.A005_SetArgumentAction_Value();
}
[Epicor.Customization.CustomCode]
private System.String A005_SetArgumentAction_Value()
{
return ("Header rows: " + dsReq.ReqHead.Count.ToString());
}
}
}
Any thoughts?











