Get Current Record ID syntax

// Begin Wizard Added Module Level Variables **

private EpiDataView edvProjCst;
private string curProjectID;

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **
ButtonTool btnOAWRefresh;

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

	this.edvProjCst = ((EpiDataView)(this.oTrans.EpiDataViews["ProjectCst"]));
	var currentRow = edvProjCst.dataView[edvProjCst.Row];
	this.curProjectID = currentRow["ProjectID"].ToString(); 

	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls

	// End Wizard Added Custom Method Calls

}

Above throws error: Exception has been thrown by the target of an invocation.

Is my code all wrong or is it because there is no record when the form first opens?

There is no record on when the screen loads.
What’s your end goal?

I just need the ProjectID of the currently displayed record to pass to a stored procedure.

Red flag a little bit, but ok

When do you need it? That is at what point? How do you want to “trigger it”

Care to give a bit more of a bigger scope to the project? Most of us see things like Stored Procedure or DB access from the Client and freak out

It’s all UD fields - not touching any Epicor ‘stuff’! I have it figured out I believe! Thank you for your time!

ok even if it is just UD fields if I am understanding you correctly you are running a stored procedure from within a customization that is accessing the Back end directly from the Front End.

That is generally not a good idea, one option would be to run a BPM that then calls your stored procedure just throwing it out there

Can I run a BPM from a toolbar button? There is no BPM associated with what I am trying to do.

Sure you can run a BPM from anywhere or better yet a UBAQ to execute your code.
What is it you are trying to do ?

I should’ve said - can I run a BPM from a custom toolbar button? It doesn’t show up in trace log.
I haven’t seen a UBAQ defined or mentioned anywhere. OK I see it’s an Updateable BAQ. I don’t know enough yet to know the difference.

my objective:
Our accountants want to see the Project Costs broken down by labor types, material types.
Ideally when the user selects the ‘Build Project Analysis’ on the Project Entry form my process would run and update a bunch of ud fields which will be displayed on the Project Cost form.

I have it working via a custom toolbar button which executes a stored procedure.

BUT, if there is a ‘safer’, better way to do it I am open to suggestions. And LOTS of help because I have spent a lot of time on this - including having to completely start over at one point, and I do not know this C# yet.

UBAQ Updatable BAQ
And yes you can trigger a BPM from anywhere. On your toolbar click you just invoke the method which has the BPM attached to.
(or since you are in 10.2.500 you can instead trigger a function which is wayyyyy better than a UBAQ)

No method associated with the epicor toolbar button or my custom toolbar button.

what/how is this done - "you can instead trigger a function "

Epicor functions

Were introduced in 500 and can be triggered to run server side code. (see above post) they are triggered via a REST call.

I initially was going down the path of using a data directive, but I couldn’t get past building all the queries in C# - lots of joining and grouping and summing - it was a mess. So I gave up on that. Can I call a stored procedure from a Data Directive? How do I do that?

Yes you can, however again generally not advised… it violates your support agreement if you are updating the Db outside the business logic.

What does the store procedure do? We can help you build the C# if you tell us what it is you are trying to accomplish

Hi Susan,

I would highly recommend against the Stored Procedure like Jose says. Updating UD fields or tables is done all the time and people here can help you with it. Hiding SPs in your database makes it difficult for someone in the future to maintain the system if you’re out on vacation… Epicor can’t help you if you have issues with the system either.

I need calculated values for each of the fields in uploaded image, except Manual and Budget which are manually entered - by Project. I haven’t even gotten that far yet besides a couple basic actual labor hours type query which still involves multiple tables.

With all those fields it’s going to take forever to run I am trying to keep it as compact as possible… hence the stored procedure.

An Epicor Function looks exactly like at stored procedure - very compact. You can go with what you know and at least you are now aware of the risks of using a stored procedure.