Can't seem to get the adapterPO.ChangeApproveSwitch to work?

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);

// Declare and Initialize Variables
bool approveValue = false;
System.String violationMsg;

// Call Adapter method
bool result = adapterPO.ChangeApproveSwitch(approveValue, out violationMsg);
adapterPO.Update();
oTrans.Update();

did you try and set the RowMod = ‘U’?

And set the Approved value to “A” or “U”

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();

just cuz i have to ask… you ran a trace file from the UI to take a look at methods and params normally being called?

Here is what it sends to the log when I use the UI to unapproved a PO…

tracePacket>
businessObject>Erp.Proxy.BO.POImpl
methodName>ChangeApproveSwitch
returnType>System.Void
localTime>9/22/2016 13:08:19:7743097 PM

parameter name=“ApproveValue” type=“System.Boolean”>
parameter name=“ViolationMsg” type=“System.String”>
parameter name=“ds” type=“PODataSet”>
PODataSet xmlns=“http://www.epicor.com/Ice/300/BO/PO/PO” />

paramDataSetChanges>
paramDataSet name=“ds” useDataSetNbr=“0”>
changedValue tableName=“POHeader” rowState=“Modified” rowNum=“0” colName=“RowMod”>
changedValue tableName=“POHeader” rowState=“Modified” rowNum=“0” colName=“UD_SysRevID”>

businessObject>Erp.Proxy.BO.POImpl
methodName>Update
returnType>System.Void
parameters>
parameter name=“ds” type=“PODataSet”>
PODataSet xmlns=“http://www.epicor.com/Ice/300/BO/PO/PO” />

paramDataSetChanges>
paramDataSet name=“ds” useDataSetNbr=“0”>
changedValue tableName=“POHeader” rowState=“Modified” rowNum=“0” colName=“ReadyToPrint”>
changedValue tableName=“POHeader” rowState=“Modified” rowNum=“0” colName=“Approve”>
changedValue tableName=“POHeader” rowState=“Modified” rowNum=“0” colName=“RowMod”>
changedValue tableName=“POHeader” rowState=“Modified” rowNum=“0” colName=“UD_SysRevID”>

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?

i notice you are declaring a datatable, maybe it wants to work with a dataset?
DataSet ds = dataset.Tables[“POHeader”]; ?

also curious what the ForLoop is for? GetbyID returns a single POHeader record, if you were passing a list i could see it…

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

Good point. I just copied the code that I was using to loop through the PO Releases and changed it up for the PO Header.

David ,

this should work for you

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Erp.BO;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	private EpiBaseAdapter oTrans_adapter;
    EpiDataView edvPOHeader;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization
		this.oTrans_adapter = ((EpiBaseAdapter)(this.csm.TransAdaptersHT["oTrans_adapter"]));
        this.edvPOHeader = ((EpiDataView)(this.oTrans.EpiDataViews["POHeader"]));
		// Begin Wizard Added Custom Method Calls

		this.toad.Click += new System.EventHandler(this.toad_Click);
		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		this.toad.Click -= new System.EventHandler(this.toad_Click);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void tool_Click(object sender, System.EventArgs args)
    {
        POAdapter adapterPO = new POAdapter(this.oTrans);
        adapterPO.BOConnect();
        PODataSet POdata;
        int intPONumber = Convert.ToInt32(edvPOHeader.dataView[edvPOHeader.Row]["PONum"]);
        adapterPO.GetByID(intPONumber);
        POdata = adapterPO.POData;
        // Declare and Initialize Variables
        System.String violationMsg;
        // Call Adapter method    
        if (POdata != null)
        {
            if (POdata.Tables["POHeader"] != null && POdata.Tables["POHeader"].Rows.Count > 0)
            {
                string cOrderChangedMsgText = string.Empty;
                PODataSet.POHeaderRow poHd = (PODataSet.POHeaderRow)POdata.POHeader[0];
                poHd.ApprovalStatus = "U";
                poHd.RowMod = "U";
                adapterPO.ChangeApproveSwitch(false, out violationMsg);
                adapterPO.chkPODatesChanges(out cOrderChangedMsgText, "POHeader");
                adapterPO.Update();
                oTrans.Refresh();
            }
        }
        // Cleanup Adapter Reference
        adapterPO.Dispose();
    }
}

Woot Woot! Thank you very much for your assistance. The codes supplied worked like a champ!

glad to hear it, feel free to mark the topic as solved :slight_smile: