Updating EpiCurrencyConver field

I have an external BAQ I am using to feed a dataset to populate the Manual Cost fields. The hours are numeric editor fields and work fine. I am having issues populating the EpiCurrencyConver fields. I have them declared like this:

EpiCurrencyConver MtlCost = (EpiCurrencyConver)csm.GetNativeControlReference(“bd595272-a2e2-4417-bd1e-b326702cce3e”);

Then I try to fill them like this:

MtlCost.Text = dr[“Calculated_Total_Material”].ToString();

But nothing shows up. It stays zeros. It does not visibly throw an error.

Any idea how to properly populate the EpiCurrencyConver field?

Maybe if I clarify a bit more someone might have some ideas. On the Project Entry form under the Project Costs tab there is a column of fields titled Manual Cost to Complete. I have added a button to the form that will call an external BAQ to retrieve this data. When I try to fill it in two things happen. First, the hours fill in fine but the costs do not. Second, if I try to save it the hours aren’t saved (nothing is saved). I have tried updating the fields in the ProjectCst table directly in an updatable BAQ to get the data in with the same result - it never gets saved.

I assume there is some function going on in the background to take the user input and process it. How can I replicate the user inputting the data into these fields? I have tried creating a separate text box and binding the same field to it as the form field but that does not work either.

See if this helps you: EpiCurrencyConver - ERP 10 - Epicor User Help Forum (epiusers.help)

I was looking at this article as you sent it. I see the binding to the Doc part of it, but I’m new to Epicor and I am not familiar with the adapter stuff. Let me explain what I am doing to see where I may be misguided.

I have a button on the Project Cost tab to call my external BAQ. This BAQ returns 3 records that I will walk through to fill in the data on the form. I was thinking I could do something like the code below, but even though it looks like it fills in the data for the hours fields (not epiCurrencyConver) it still doesn’t save it. It does not populate the epiCurrencyConver fields at all. I assume I would need to use the adapter to save it but I am not sure how to put that into my code. I think it would be within the Project adapter since I don’t see a ProjectCst one when I look at the wizard.

I am fine with the user clicking the Save button to commit the changes that way they can modify it if necessary. But how do I get the data into those fields and get them to save if they don’t type in the data?

Here is the code I have in the OnClick event of the button:

		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("ProjectID", Cobra_Project , "nvarchar",false, Guid.NewGuid(),"A");
		dqa.ExecuteByID("Cobra_Project_Cost",qeds);
		DataTable dtCobra = dqa.QueryResults.Tables["Results"];
		foreach (DataRow dr in dtCobra.Rows)
		{
			if (dr["Calculated_Code_Type"].ToString() == "LABOR")
			{
				LbrHours.Text = dr["Calculated_Total_Labor_Hours"].ToString();
				LbrBurHours.Text = dr["Calculated_Total_Labor_Hours"].ToString();
				MessageBox.Show( dr["Calculated_Total_Labor_Dollars"].ToString());
				epiTestFieldA.Text = dr["Calculated_Total_Labor_Dollars"].ToString();
				BurCost.Text = dr["Calculated_Total_Labor_Burden"].ToString();
			}
			else if (dr["Calculated_Code_Type"].ToString() == "ODC")
			{
				//MessageBox.Show("ODC");
				ODCCost.Text = dr["Calculated_Total_ODC"].ToString();
			}
			else
			{
				//MessageBox.Show("MTL");
				MtlCost.Text = dr["Calculated_Total_Material"].ToString();
				MtlBurCost.Text = dr["Calculated_Total_Material_Burden"].ToString();
			}
		}'''

Instead of

.Text

try

.Value

Additionally, if you want it to save, you have to write it to the dataset, not the control.

Assuming the dataview is named ProjectCst (you’d have to verify), you can do something like:

var edv = oTrans.Factory("ProjectCst");

edv.dataView[edv.Row].BeginEdit();
// The DataViewColumnName would be whatever the EpiBinding is.
// For example, if it's ProjectCst.LaborHours, then put ["LaborHours"]
edv.dataView[edv.Row]["DataViewColumnName"] = dr["Calculated_Total_Labor_Hours"].ToString();
edv.dataView[edvRow].EndEdit();
1 Like

First, I did try Value but I got an error that it is not a part of that class.

I did change my code to use the dataset you proposed and it worked great! Thanks so much!

1 Like

Similar results when trying to use .Value for retrieving value of the control,

‘Ice.Lib.Framework.EpiCurrencyConver’ does not contain a definition for ‘Value’ and no extension method ‘Value’ accepting a first argument of type ‘Ice.Lib.Framework.EpiCurrencyConver’ could be found (are you missing a using directive or an assembly reference?)

You may have to cast it to an EpiCurrencyEditor.

EpiCurrencyEditor myCurField = (EpiCurrencyEditor)csm.GetNativeControlReference("Your_Control's_GUID");

myCurField.Value;

Ah, Object Exploder, let me take a look at that. I believe in my case I’m referencing a EpiCurencyConver type control, but this is great info and I’m probably wrong but either way this points out the direction for due diligence on my part. Thank you for that.

They don’t have an EpiCurrencyConver in the Object Explorer which is why I was suggesting you try to cast it as an EpiCurrencyEditor.

1 Like

It passes the code test, but unfortunately it fails on actual execution,

Inner Exception Message: Unable to cast object of type ‘Ice.Lib.Framework.EpiCurrencyConver’ to type ‘Ice.Lib.Framework.EpiCurrencyEditor’.

For this ‘experiment’ I can change my custom field to EpiCurrencyEditor, which will reach-around this specific error.

But the next hurdle of actually ‘updating’ the UnitPrice EpiCurrencyConver data+control is going to arise.

So, to get the value of the control (not the binding), you will need to use reflection.

using System.Reflection;

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **
	EpiCurrencyConver field = (EpiCurrencyConver)csm.GetNativeControlReference("c7457526-103e-4f8a-a194-c08416968354");

	EpiCurrencyEditor baseCurEdit = (EpiCurrencyEditor)field.GetType().GetField("curBaseCurrency",BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic).GetValue(field);   

	MessageBox.Show(baseCurEdit.Value.ToString());
}

image

If you want the value from the database binding, steer clear of that method as you cannot update the database with that code.
You would need to get the value from the EpiBinding.

// Change ProjectCst to your view name
var edv = oTrans.Factory("ProjectCst");

edv.dataView[edv.Row].BeginEdit();
// The DataViewColumnName would be whatever the EpiBinding is.
// For example, if it's ProjectCst.LaborHours, then put ["LaborHours"]
edv.dataView[edv.Row]["DataViewColumnName"] = dr["Calculated_Total_Labor_Hours"].ToString();
edv.dataView[edvRow].EndEdit();

Just for reference, the EpiCurrencyConver is a composite control that encapsulates 5 different EpiCurrencyEditor controls. You will need to reflect on each different control name to get the value of each of the 5.
Base: curBaseCurrency
Doc: curDocCurrency
Rpt1: curRpt1
Rpt2: curRpt2
Rpt3: curRpt3

2 Likes

That is fantastic! Thank you so very much!

I was researching my way around and I had found this article on epicweb that talks about the ‘5’ fields and had seen the fields using the FSMisc table as an example, in the data dictionary viewer.

I’ll add the Reflection example into my sample code and learn some things.

I supposed my next bit of research is going to be to determine what is necessary after update of the dataset, to make the control show the new value - if it is save and refresh or if the EndEdit encapsulates all that - assuming that there isn’t currently a way to update the control’s value without saving. Saving is totally a valid option in my situation, just wanting to make sure.

This has been a great learning experience, thank you for taking your time to demonstrate.

Okay–so using reflection to get and set the value of the control will only change what you see visually on the screen. It will not update the database.

If you’re looking to update the actual database field and display it, you need to update the corresponding field in the dataView. Do not try and use the first method for that; it won’t do what you want.

You should be fine doing The Begin/End edit stuff. To refresh the screen, I believe you need oTrans.Update(); and oTrans.Notify(); after to get the GUI to refresh.

1 Like

Aha! I finally got it! Thank you, again.

1 Like