Quantity Adjust Transaction using C#

Trying to complete an inventory transaction using C#, but running into walls. When I run the code, I get this error:

I went back through my code and added all those fields in with values that mimic a similar Qty Adjust transaction made through the form. I still get the error. Has anyone made this work before? Code below:

private void TEST_Click(object sender, System.EventArgs args)
{
		PartTranAdapter IQA = new PartTranAdapter(oTrans);
		IQA.BOConnect();

		int time = Convert.ToInt32(DateTime.Now.Hour)*60*60 + Convert.ToInt32(DateTime.Now.Minute)*60 + Convert.ToInt32(DateTime.Now.Second);

		IQA.GetNewPartTran(DateTime.Now,time);

		DataRow qad = IQA.PartTranData.PartTran[IQA.PartTranData.PartTran.Rows.Count-1];
			qad["Company"] = "TS-LLC";
			qad["TranNum"] = "8641321";
			qad["PartNum"] = "90006";
			qad["WareHouseCode"] = "DEN03";
			qad["BinNum"] = "Bin03";
			qad["TranClass"] = "A";
			qad["TranType"] = "ADJ-QTY";
			qad["InventoryTrans"] = true;
			qad["TranDate"] = DateTime.Now;
			qad["TranQty"] = 1;
			qad["UM"] = "EACH";
			qad["EntryPerson"] = "TruGlass";
			qad["InvAdjReason"] = "1060";
			qad["CostMethod"] = "A";
			qad["JobNum"] = "";
			qad["AssemblySeq"] = 0;
			qad["JobSeqType"] = "M";
			qad["JobSeq"] = 0;
			qad["PackType"] = "";
			qad["PackNum"] = 0;
			qad["PackLine"] = 0;
			qad["PONum"] = 0;
			qad["POLine"] = 0;
			qad["PORelNum"] = 0;
			qad["OrderNum"] = 0;
			qad["OrderLine"] = 0;
			qad["OrderRelNum"] = 0;
			qad["PartDescription"] = @"MDF - 1.75"" X 5' X 8'";
			qad["RevisionNum"] = "1";
			qad["VendorNum"] = 0;
			qad["POReceiptQty"] = 0;
			qad["PackSlip"] = "";
			qad["InvoiceNum"] = "";
			qad["InvoiceLine"] = 0;
			qad["DimCode"] = "";
			qad["DUM"] = "";
			qad["DimConvFactor"] = 1;
			qad["FiscalPeriod"] = 0;
			qad["JournalNum"] = 0;
			qad["DMRNum"] = 0;
			qad["ActionNum"] = 0;
			qad["RMANum"] = 0;
			qad["JournalCode"] = "";
			qad["Plant"] = "MfgSys";
			qad["Plant2"] = "MfgSys";
			qad["CallNum"] = 0;
			qad["CallLine"] = 0;
			qad["RMALine"] = 0;
			qad["CustNum"] = 0;

		IQA.Update();
		IQA.Dispose();
		MessageBox.Show("DONE");

	}

You are better off turning on client tracing, doing the transaction in the erp and then compare the dataset being sent to the Update to yours.

2 Likes

Please do yourself a favor and do a Trace then follow the trace to a T

You are using the wrong business object, you can’t write directly to PartTran

Like @Jonathan said, do a trace and start there, doing a direct Part Tran write like you are attempting is going to cause all sorts of pain and suffering (if you even get it to work).

1 Like

I started that route, and I ended up with that BO just from digging around.

I am used to a “GetNew…” sort of object, which I couldn’t find. I started out with trying GetInventoryQtyAdj(), but it isn’t actually returning any data. This was the original trace that I was trying to follow, but that is where I stalled.

<tracePacket>
  <businessObject>Erp.Proxy.BO.InventoryQtyAdjImpl</businessObject>
  <methodName>GetInventoryQtyAdjBrw</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>Erp.Tablesets.InventoryQtyAdjBrwTableset</returnType>
  <localTime>3/30/2022 15:50:49:2204088 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="91" roundTrip="85" channel="0" bpm="0" other="6" />
  <retries>0</retries>
  <parameters>
    <parameter name="partNum" type="System.String"><![CDATA[90006]]></parameter>
    <parameter name="wareHouseCode" type="System.String"><![CDATA[DEN03]]></parameter>
    <parameter name="primaryBin" type="System.String"><![CDATA[]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.InventoryQtyAdjImpl</businessObject>
  <methodName>CheckSN</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>3/30/2022 15:50:49:3217810 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="29" roundTrip="28" channel="0" bpm="0" other="1" />
  <retries>0</retries>
  <parameters>
    <parameter name="partNum" type="System.String"><![CDATA[90006]]></parameter>
    <parameter name="warehouseCode" type="System.String"><![CDATA[DEN03]]></parameter>
    <parameter name="serialNumbersRequired" type="System.Boolean"><![CDATA[False]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Ice.Proxy.Lib.BOReaderImpl</businessObject>
  <methodName>GetList</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Data.DataSet</returnType>
  <localTime>3/30/2022 15:50:49:3653215 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="34" roundTrip="24" channel="0" bpm="0" other="10" />
  <retries>0</retries>
  <parameters>
    <parameter name="serviceNamespace" type="System.String"><![CDATA[Erp:BO:TranDocType]]></parameter>
    <parameter name="whereClause" type="System.String"><![CDATA[((Inactive = false) AND (SystemTranID = 'StQtyAdj'))]]></parameter>
    <parameter name="columnList" type="System.String"><![CDATA[SystemTranID,TranDocTypeID,Description]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.InventoryQtyAdjImpl</businessObject>
  <methodName>GetAvailTranDocTypes</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>3/30/2022 15:50:49:3883164 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="23" roundTrip="22" channel="0" bpm="0" other="1" />
  <retries>0</retries>
  <parameters>
    <parameter name="AvailTypes" type="System.String"><![CDATA[]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Ice.Proxy.Lib.ClientCacheImpl</businessObject>
  <methodName>GetClassInformation</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>Ice.Tablesets.ClassAttributeTableset</returnType>
  <localTime>3/30/2022 15:50:56:7338937 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="49" roundTrip="48" channel="0" bpm="0" other="1" />
  <retries>0</retries>
  <parameters>
    <parameter name="token" type="System.String"><![CDATA[Reason]]></parameter>
    <parameter name="additionalTokens" type="System.String[]"><![CDATA[]]></parameter>
    <parameter name="objectAccess" type="System.Boolean"><![CDATA[False]]></parameter>
    <parameter name="restrictedColumns" type="System.String"><![CDATA[]]></parameter>
    <parameter name="restrictedMethods" type="System.String"><![CDATA[]]></parameter>
    <parameter name="additionalTokenAccess" type="System.String"><![CDATA[]]></parameter>
    <parameter name="nameSpace" type="System.String"><![CDATA[Erp:BO]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Ice.Proxy.Lib.BOReaderImpl</businessObject>
  <methodName>GetList</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Data.DataSet</returnType>
  <localTime>3/30/2022 15:50:56:7751663 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="41" roundTrip="41" channel="0" bpm="0" other="0" />
  <retries>0</retries>
  <parameters>
    <parameter name="serviceNamespace" type="System.String"><![CDATA[Erp:BO:Reason]]></parameter>
    <parameter name="whereClause" type="System.String"><![CDATA[ReasonType='M']]></parameter>
    <parameter name="columnList" type="System.String"><![CDATA[ReasonCode,ReasonType,Description]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Ice.Proxy.Lib.ClassAttributeImpl</businessObject>
  <methodName>GetAttributes</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>Ice.Tablesets.ClassAttributeTableset</returnType>
  <localTime>3/30/2022 15:50:58:6540820 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="27" roundTrip="26" channel="0" bpm="0" other="1" />
  <retries>0</retries>
  <parameters>
    <parameter name="classNames" type="System.String"><![CDATA[WhseBin]]></parameter>
    <parameter name="nameSpace" type="System.String"><![CDATA[Erp.BO]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.WhseBinImpl</businessObject>
  <methodName>GetRows</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>Erp.Tablesets.WhseBinTableset</returnType>
  <localTime>3/30/2022 15:50:58:6873405 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="157" roundTrip="72" channel="78" bpm="0" other="7" />
  <retries>0</retries>
  <parameters>
    <parameter name="whereClauseWhseBin" type="System.String"><![CDATA[WareHouseCode='DEN03' AND BinNum='bin03']]></parameter>
    <parameter name="whereClauseWhseBinAttch" type="System.String"><![CDATA[]]></parameter>
    <parameter name="pageSize" type="System.Int32"><![CDATA[0]]></parameter>
    <parameter name="absolutePage" type="System.Int32"><![CDATA[0]]></parameter>
    <parameter name="morePages" type="System.Boolean"><![CDATA[False]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.InventoryQtyAdjImpl</businessObject>
  <methodName>NegativeInventoryTest</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>3/30/2022 15:50:58:8546859 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="50" roundTrip="48" channel="0" bpm="0" other="2" />
  <retries>0</retries>
  <parameters>
    <parameter name="pcPartNum" type="System.String"><![CDATA[90006]]></parameter>
    <parameter name="pcWhseCode" type="System.String"><![CDATA[DEN03]]></parameter>
    <parameter name="pcBinNum" type="System.String"><![CDATA[bin03]]></parameter>
    <parameter name="pcLotNum" type="System.String"><![CDATA[]]></parameter>
    <parameter name="pcPCID" type="System.String"><![CDATA[]]></parameter>
    <parameter name="pcDimCode" type="System.String"><![CDATA[EACH]]></parameter>
    <parameter name="pdDimConvFactor" type="System.Int32"><![CDATA[1]]></parameter>
    <parameter name="ipSellingQuantity" type="System.Decimal"><![CDATA[1.000]]></parameter>
    <parameter name="pcNeqQtyAction" type="System.String"><![CDATA[]]></parameter>
    <parameter name="pcMessage" type="System.String"><![CDATA[]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.InventoryQtyAdjImpl</businessObject>
  <methodName>PreSetInventoryQtyAdj</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>3/30/2022 15:50:58:9040680 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="33" roundTrip="24" channel="0" bpm="0" other="9" />
  <retries>0</retries>
  <parameters>
    <parameter name="ds" type="Erp.BO.InventoryQtyAdjDataSet">
      <InventoryQtyAdjDataSet xmlns="http://www.epicor.com/Ice/300/BO/InventoryQtyAdj/InventoryQtyAdj" />
    </parameter>
    <parameter name="requiresUserInput" type="System.Boolean"><![CDATA[False]]></parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.InventoryQtyAdjImpl</businessObject>
  <methodName>SetInventoryQtyAdj</methodName>
  <appServerUri>net.tcp://tsd-epc1_t/Epicor/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>3/30/2022 15:50:58:9372485 PM</localTime>
  <threadID>1</threadID>
  <executionTime total="538" roundTrip="527" channel="0" bpm="0" other="11" />
  <retries>0</retries>
  <parameters>
    <parameter name="ds" type="Erp.BO.InventoryQtyAdjDataSet">
      <InventoryQtyAdjDataSet xmlns="http://www.epicor.com/Ice/300/BO/InventoryQtyAdj/InventoryQtyAdj" />
    </parameter>
    <parameter name="partTranPKs" type="System.String"><![CDATA[]]></parameter>
  </parameters>
</tracePacket>

You don’t need to do GetNew since you aren’t creating anything new you are reducing qty onhand.

Follow that trace the first call returns a Qty adjustment dataset and then you use that to do the rest

Okay. Let me give that a shot. In my mind I had that I had to create a new record versus modify what exists, so I think that is why I got lost. I will give this a shot!

Thank you :slight_smile:

try
{										
	InventoryQtyAdjAdapter adInvQtyAdj = new InventoryQtyAdjAdapter(this.oTrans);
	adInvQtyAdj.BOConnect();
	
   	 Erp.BO.InventoryQtyAdjDataSet dsInvQtyAdj = adInvQtyAdj.InventoryQtyAdjData;
     dsInvQtyAdj = adInvQtyAdj.GetInventoryQtyAdj(sPartNo, uomCode);
	
	 DataRow drInvAdjQty = dsInvQtyAdj.InventoryQtyAdj[0];	     	   
	
	 drInvAdjQty["PartNum"] = sPartNo;
	 drInvAdjQty["LotNum"] = sLotNo;
	 drInvAdjQty["WareHseCode"] = sFromWhseCode;
	 drInvAdjQty["BinNum"] = sFromBinNum;
	 drInvAdjQty["AdjustQuantity"] = -1 * nWriteOffQty;
	 drInvAdjQty["ReasonCode"] = "PROD";
	 drInvAdjQty["Reference"] = sReference;
	 drInvAdjQty["RowMod"] = "U";
	
	 adInvQtyAdj.SetInventoryQtyAdj(dsInvQtyAdj, out sPKTrans);
	
     adInvQtyAdj.Dispose();
	
} catch (System.Exception ex)
{
	ExceptionBox.Show(ex);
}
2 Likes

That is it. Thank you!

I had an Update() instead of the SetInventoryQtyAdj. I had tried that object before, but not in that place. Thank you so much!

Hi,

Do I understood correctly, by this you are skiping NegativeInventoryTest is this ok to skip this method?

Depends entirely on your business process. In that example I had probably just checked the quantity above to ensure it was valid, before processing it.

Good practice is to follow all of the same calls that Epicor makes, unless you have a good reason not to and understand the process fully.

1 Like