I’m trying to be able to approve/unapproved a Purchase Order via C# in Epicor 10. I’m able to get ahold of a PO with the POAdapter, but I can’t seem to get following switch method to work adapterPO.ChangeApproveSwitch(approveValue, out violationMsg);?
When I run this nothing changes on the PO specified and I get a message from the switch method that no changes were made.
private void CallPOAdapterChangeApproveSwitchMethod()
{
try
{
// Declare and Initialize EpiDataView Variables
// Declare and create an instance of the Adapter.
POAdapter adapterPO = new POAdapter(this.oTrans);
adapterPO.BOConnect();
int intPONumber = 5003180;
System.Data.DataSet adapterPODS = adapterPO.GetData(intPONumber);
I tried to add the RowMod = “U” and set the ApprovalStatus to “U” but I still can’t get it to unapproved the PO. I can however Approve an unapproved PO by setting Approve = true and the ApprovalStatus = “A”, I just can’t go the other way. Here is the message that I think the switch is throwing…
[cid:image001.png@01D214BF.12CA1BB0]
// Declare and create an instance of the Adapter
POAdapter adapterPO = new POAdapter(this.oTrans);
adapterPO.BOConnect();
int intPONumber = 5003180;
System.Data.DataSet dataset = adapterPO.GetData(intPONumber);
bool poAdapt = adapterPO.GetByID(intPONumber);
if((poAdapt))
{
MessageBox.Show("PONum from POAdapt = " + adapterPO.POData.POHeader[0]["PONum"].ToString() + " Status from POAdapt = " + adapterPO.POData.POHeader[0]["ApprovalStatus"].ToString());
}
// Declare and Initialize Variables
System.String violationMsg;
// Call Adapter method
bool result = adapterPO.ChangeApproveSwitch(false, out violationMsg);
if (dataset != null)
{
if(dataset.Tables["POHeader"]!= null && dataset.Tables["POHeader"].Rows.Count > 0)
{
DataTable dt = dataset.Tables["POHeader"];
for (int i = 0; i < dt.Rows.Count; i++)
{
MessageBox.Show("B4 Adapter Approval Status " + adapterPO.POData.POHeader[i]["ApprovalStatus"].ToString());
//dt.Rows[i]["Approve"] = false;
dt.Rows[i]["ApprovalStatus"] = "U";
dt.Rows[i]["RowMod"] = "U";
MessageBox.Show("After Adapter Approval Status " + adapterPO.POData.POHeader[i]["ApprovalStatus"].ToString());
adapterPO.Update();
oTrans.Update();
}
}
}
// Cleanup Adapter Reference
adapterPO.Dispose();
There seems to be a parameter name=“ds” type=“PODataSet” that needs to be sent to the ChangeApproveSwitch, but I don’t really know what to pass via code?
We use a Service Connect workflow to unlock releases once a month so we can catch specific PO changes. In order to do this, approved POs need to be un-approved , the releases unlocked and the PO approved again.
The steps taken by the workflow are:
GetRows where PONum =
ChangeApproveSwitch using the ApproveValue and the POHeader.Approve value set to be same as the ApproveValue parameter in the method call, POHeader.ApprovalStatus set to ‘U’ or ‘A’ depending on ApproveValue and POHeader.RowMod set to ‘U’
After the ChangeApproveSwitch method is invoked, the Update method is invoked
so for us to change the approval, the method needs to be called with 3 fields changed in the POHeader table followed by the Update method