AfterFieldChange code error

Hello

I am trying to add some code that is going to update some values on a quote after a certain case is met. When entering the value in the field I am being met with a “Object reference not set to an instance of an object” Application error.

Here is the code I added:

private void QuoteHed_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		// ** Argument Properties and Uses **
		// args.Row["FieldName"]
		// args.Column, args.ProposedValue, args.Row
		// Add Event Handler Code
		switch (args.Column.ColumnName)
		{
                case "PrevWageRate_c":     //testing IC 1/4/10
				
				    var prevWageRate = Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row] ["PrevWageRate_c"]);
				
				    if(Convert.ToBoolean(edvQuoteHed.dataView[edvQuoteHed.Row]["PrevWage_c"]) == true)
					{
					edvQuoteOpDtl.dataView[edvQuoteOpDtl.Row]["OverrideRates"] = true;
					edvQuoteOpDtl.dataView[edvQuoteOpDtl.Row]["ProdLabRate"] = prevWageRate;
					}
			    break;

There are other cases below it that work fine.

I have added

private EpiDataView edvQuoteOpDtl;

this.edvQuoteOpDtl = ((EpiDataView)(this.oTrans.EpiDataViews[“QuoteOpDtl”]));

this.edvQuoteOpDtl = null;

in the necessary places along with the exisiting EpiDataView for QuoteHed.

Do I have to add BO to this case to get it to function how I want?

Try using the above, instead of this

edvQuoteHed.dataView[edvQuoteHed.Row] ["PrevWageRate_c"]

I replaced that line with this:

var prevWageRate = Convert.ToDecimal(args.ProposedValue);

and am still getting the same Application Error:

Try dropping in some message boxes to pop up so you can narrow it down to a specific problem line.

1 Like

Instead of explicitly trying to access the dataview, use the passed parameter:
args.Row[“YourField”] = xxx

Update - nevermind I see you are also accessing the Dtl view. Make sure you check first that Row >= 0

if(edvQuoteOpDtl != null && edvQuoteOpDtl.Row >= 0)
{
Change your dtl

}

Was looking through field help to make sure that I had the right information and saw that the epibinding and db field are different for the fields I am trying to change:

Ended up combining what @josecgomez and @Chris_Conn suggested and it seems to be working for me right now. Ended up with this for the case statement:

 case "PrevWageRate_c":     //testing IC 1/4/10
				
				//var prevWageRate = Convert.ToDecimal(edvQuoteHed.dataView[edvQuoteHed.Row]["PrevWageRate_c"]);
				var prevWageRate = Convert.ToDecimal(args.ProposedValue);
				var prevWage = Convert.ToBoolean(edvQuoteHed.dataView[edvQuoteHed.Row]["PrevWage_c"]);
				
				if(prevWage = true && prevWageRate != 0)
					{
						if(edvJobOpDtl != null && edvJobOpDtl.Row >= 0)
						{						
							edvJobOpDtl.dataView[edvJobOpDtl.Row]["OverrideRates"] = true;
							edvJobOpDtl.dataView[edvJobOpDtl.Row]["ProdLabRate"] = prevWageRate;
						}
					}
			break;

Ended up changing QuoteOpDtl to JobOpDtl along with the change suggested.

Thank you. You guys always save me.

3 Likes

You got a bug in your code :slight_smile: which you wont notice yet, but soon you will.

3 Likes

:sweat_smile:

Can I add an easy foreach statement in here without blowing it up? ?There are multiple lines that need to take the value and it is currently doing the last one.

foreach(DataRow dr in edvQuoteDtl.Rows)

Is what I would have written.

Also now when I click save the values disappear? Wasn’t happening to me last week.

image

Edit:

for(int i = 0; i < edvJobOpDtl.dataView.Count; i++)

I had pasted the wrong code up above.

This should go through the rows the way I want correct?

You’re close, you’ll need

foreach(DataViewRow dr in edvQuoteDtl.dataView)
or
foreach(DataRow dr in edvQuoteDtl.dataView.Table.Rows)

Thanks.

I think I had tried foreach(DataRow dr in edvQuoteDtl.dataView) before and got a comp error.

Now I know why! LOL

1 Like

Still doesn’t seem to be applying it to all the lines in the quote… I have to be missing something that I am not seeing. And I am still seeing those 2 boxes values disappear as well…

This is starting to get frustrating haha.

Although when there is only 1 line everything is fine all fields have and retain values.

Give us a little more code. Works for me. I use the DataViewRow version on QuoteQty, QuoteMtl etc…

This is what I currently have:

case "PrevWageRate_c":     //testing IC 1/4/10
				
				var prevWage = Convert.ToBoolean(edvQuoteHed.dataView[edvQuoteHed.Row]["PrevWage_c"]);
				var prevWageRate = Convert.ToDecimal(args.ProposedValue);
				
				if(prevWage == true && prevWageRate != 0)
					{
						if(edvJobOpDtl != null && edvJobOpDtl.Row >= 0 && Convert.ToBoolean(edvQuoteDtl.dataView[edvQuoteDtl.Row]["ReadyToQuote"]) == false)
						{
							foreach(DataRow dr in edvJobOpDtl.dataView.Table.Rows)
							{		
							edvJobOpDtl.dataView[edvJobOpDtl.Row]["OverrideRates"] = true;
							edvJobOpDtl.dataView[edvJobOpDtl.Row]["ProdLabRate"] = prevWageRate;
							}							
						}
					}
			break;

It seems to work on quotes with 1 line. Once it is greater than 1 line the values in the 2 boxes in summary disappear and the other lines do not get the new rate and the override.

Does the DataViewRow version require different coding to work? I’ve only ever used DataRow.

I always do mine on the DataViewRow, I dont think it should matter.

foreach (DataRowView drJM in edvJM.dataView)
{
	// Variables
	decimal vQP = Convert.ToDecimal(drJM["QtyPer"]);
	string vPC = drJM["Class"].ToString();

	// Calculate Per Order & Quantity Per Year
	drJM["MtlCalcQtyOrder"] = Math.Round(vQQ * vQP, 2);
	drJM["MtlCalcQtyYear"] = Math.Round(vSEQ * vQP, 2);
}

But anyways you should be doing this in your foreach ( use dr ) lol

dr["OverrideRates"] = true;
foreach(DataRow dr in edvJobOpDtl.dataView.Table.Rows)
{		
	dr["OverrideRates"] = true;
	dr["ProdLabRate"] = prevWageRate;
}

Still a no go. First line has correct values:

Second line does not:

These are the 2 fields I need to change:

image

image

At this point I am wondering if it is something with the fields themselves. Or I am going about doing this the wrong way.

Are you sure you did:

foreach(DataRow dr in edvJobOpDtl.dataView.Table.Rows)
							{		
							dr["OverrideRates"] = true;
							dr["ProdLabRate"] = prevWageRate;
							}	

Also you may want to call a Notify or save.

Also, check a trace. There may be some supporting call when changing the Override or the values there.

Yes I made sure I did that.

Call oTrans.Notify()?

I had oTrans.Update(); and oTrans.NotifyAll(); in there earlier and there was no change.

I can run a trace as well. Just a basic one should suffice correct?

Here’s a snippet of the trace log:

<tracePacket>
  <businessObject>Erp.Proxy.BO.QuoteAsmImpl</businessObject>
  <methodName>ChangeOpDtlOverrideRates</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>1/7/2019 21:44:50:4650839 PM</localTime>
  <executionTime>12</executionTime>
  <parameters>
    <parameter name="ds" type="QuoteAsmDataSet">
      <QuoteAsmDataSet xmlns="http://www.epicor.com/Ice/300/BO/QuoteAsm/QuoteAsm" />
    </parameter>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
  <paramDataSetChanges>
    <paramDataSet name="ds" useDataSetNbr="0">
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="RowMod"><![CDATA[U]]></changedValue>
    </paramDataSet>
  </paramDataSetChanges>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.QuoteAsmImpl</businessObject>
  <methodName>ChangeOpDtlOverrideRates</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>1/7/2019 21:44:50:5000859 PM</localTime>
  <executionTime>12</executionTime>
  <parameters>
    <parameter name="ds" type="QuoteAsmDataSet">
      <QuoteAsmDataSet xmlns="http://www.epicor.com/Ice/300/BO/QuoteAsm/QuoteAsm" />
    </parameter>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
  <paramDataSetChanges>
    <paramDataSet name="ds" useDataSetNbr="0">
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="RowMod"><![CDATA[U]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="1" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="1" colName="RowMod"><![CDATA[U]]></changedValue>
    </paramDataSet>
  </paramDataSetChanges>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.QuoteAsmImpl</businessObject>
  <methodName>ChangeOpDtlOverrideRates</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>1/7/2019 21:44:50:5350909 PM</localTime>
  <executionTime>12</executionTime>
  <parameters>
    <parameter name="ds" type="QuoteAsmDataSet">
      <QuoteAsmDataSet xmlns="http://www.epicor.com/Ice/300/BO/QuoteAsm/QuoteAsm" />
    </parameter>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
  <paramDataSetChanges>
    <paramDataSet name="ds" useDataSetNbr="0">
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="RowMod"><![CDATA[U]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="1" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="1" colName="RowMod"><![CDATA[U]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="2" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="2" colName="RowMod"><![CDATA[U]]></changedValue>
    </paramDataSet>
  </paramDataSetChanges>
</tracePacket>

<tracePacket>
  <businessObject>Ice.Proxy.BO.UD02Impl</businessObject>
  <methodName>GetRows</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>UD02Tableset</returnType>
  <localTime>1/7/2019 21:44:50:5600907 PM</localTime>
  <executionTime>8</executionTime>
  <parameters>
    <parameter name="whereClauseUD02" type="System.String"><![CDATA[Key1 = 'Quote' And Key2 = '83135' BY Key1]]></parameter>
    <parameter name="whereClauseUD02Attch" 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>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Ice.Proxy.BO.UD02Impl</businessObject>
  <methodName>GetRows</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>UD02Tableset</returnType>
  <localTime>1/7/2019 21:44:50:6250962 PM</localTime>
  <executionTime>10</executionTime>
  <parameters>
    <parameter name="whereClauseUD02" type="System.String"><![CDATA[Key1 = 'Quote' And Key2 = '83135' BY Key1]]></parameter>
    <parameter name="whereClauseUD02Attch" 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>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.QuoteAsmImpl</businessObject>
  <methodName>Update</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>System.Void</returnType>
  <localTime>1/7/2019 21:44:52:0549861 PM</localTime>
  <executionTime>132</executionTime>
  <parameters>
    <parameter name="ds" type="QuoteAsmDataSet">
      <QuoteAsmDataSet xmlns="http://www.epicor.com/Ice/300/BO/QuoteAsm/QuoteAsm" />
    </parameter>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
  <paramDataSetChanges>
    <paramDataSet name="ds" useDataSetNbr="0">
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="0" colName="RowMod"><![CDATA[U]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="1" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="1" colName="RowMod"><![CDATA[U]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="2" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="2" colName="RowMod"><![CDATA[U]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="3" colName="ProdLabRate"><![CDATA[255.00]]></changedValue>
      <changedValue tableName="QuoteOpDtl" rowState="Modified" rowNum="3" colName="RowMod"><![CDATA[U]]></changedValue>
    </paramDataSet>
  </paramDataSetChanges>
</tracePacket>

<tracePacket>
  <businessObject>Erp.Proxy.BO.QuoteImpl</businessObject>
  <methodName>GetByID</methodName>
  <appServerUri>net.tcp://omsvepiazu001/E10Test/</appServerUri>
  <returnType>QuoteTableset</returnType>
  <localTime>1/7/2019 21:44:52:2399777 PM</localTime>
  <executionTime>103</executionTime>
  <parameters>
    <parameter name="quoteNum" type="System.Int32"><![CDATA[83135]]></parameter>
    <parameter name="CallContext" type="Ice.Bpm.Context.ContextDataSet">
      <ContextDataSet xmlns="http://www.epicor.com/Ice/300/Bpm/Context">
        <BpmData>
          <Number01>0</Number01>
          <SysRowID>00000000-0000-0000-0000-000000000000</SysRowID>
        </BpmData>
      </ContextDataSet>
    </parameter>
  </parameters>
</tracePacket>

I am seeing that ChangeOpDtlOverrideRates method name pop up more than once.

Also the code is acting weird when changing values. I can enter in different values into the PreWageRate box it won’t update the box but will update the lines one at a time so all boxes can have different values.I’ll put a video up of what I am talking about shortly.

Edit:

Just throwing stuff out there as I have no answers or ideas as to why I can’t go through the rows on the dataview on the jobopdtl. Does the fact that the DB field and EpiBinding are different tables have anything to do with it not going through the rows properly?

Does the afterfieldchange event only take the epibinding into account?