Screen Customization Get SysRowID?

This is on Transfer Order Work Bench. I’m trying to have a button open a webpage with the SysRowID of the current part. I’m getting Object reference not set to an instance of an object.

public class Script
{	
	private EpiDataView edvpartView;	

	public void InitializeCustomCode()
	{
		this.edvpartView = ((EpiDataView)(this.oTrans.EpiDataViews["partView"]));
		this.edvpartView.EpiViewNotification += new EpiViewNotification(this.edvpartView_EpiViewNotification);

		this.btnLaunchPartForm.Click += new System.EventHandler(this.btnLaunchPartForm_Click);
      

	}


	private void edvpartView_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
		{
			if ((args.Row > -1))
			{ 
			}
		}
	}

	private void btnLaunchPartForm_Click(object sender, System.EventArgs args)
	{	
		Process.Start("Chrome.exe", string.Format("http://our-webpage/index.php?srid={0}", (Guid)edvpartView.CurrentDataRow["SysRowID"]));   // this is the line that's failing because the (Guid)edvpartView.CurrentDataRow["SysRowID"] part, if I remove that and just hardcode something it pops open the browser like I want. 
	}   
}

I know the error is because of this: (Guid)edupartView.CurrentDataRow[“SysRowID”]
but I don’t understand why.

Also what is an EpiViewNotification? it looks like it’s a method. Does Epicor call this method anytime the view changes? If that’s the case, do I need to update edvpartView somehow?

Is edvpartView.CurrentDataRow["SysRowID"] is a GUID or String? And the string.Format() function probably needs a string and not a datatype of GUID.

A total guess at fixing it would be:

Process.Start("Chrome.exe", string.Format("http://our-webpage/index.php?srid={0}", edvpartView.CurrentDataRow["SysRowID"])); 

or

Process.Start("Chrome.exe", string.Format("http://our-webpage/index.php?srid={0}", edvpartView.CurrentDataRow["SysRowID"].ToString())); 

Thank you for taking a stab at it. Unfortunately neither of those worked. Still same error. I think the issue might be that this: edvpartView.CurrentDataRow["SysRowID"] doesn’t exist somehow.

In the initialization section I find this declaration of a private variable:
this.edvpartView = ((EpiDataView)(this.oTrans.EpiDataViews["partView"]));

In the view notification I tried this thinking that when I bring in a part with the binoculars that something would trigger but no, nothing triggered so it appears the view is not being updated which means maybe I have the wrong view? I dunno…

private void edvpartView_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
		{
			if ((args.Row > -1))
			{
				MessageBox.Show("got a record"); 
			}
			else { 
				MessageBox.Show("no record"); 
			} 
		}
	}

Here’s the object explorer, seems to show that partView is something at least, but I’m not sure what I’m looking at.

In your edvpartView_EpiViewNotification() function add the following before the first if(...) line:

MessageBox.Show(args.NotifyType.ToString());

Then you’ll be able to see what NotifyType happens when.

Note that you’ll get a bunch of pop-ups, but this is just for debugging, so you can see what fires after the part record if fetched.

Cool, now I’m learning something here. It appears to fire on the initialize method instead of AddRow method.

So I changed the if statement to this:

if ((args.NotifyType == EpiTransaction.NotifyType.AddRow) || 
        (args.NotifyType == EpiTransaction.NotifyType.Initialize)
        ){
		if ((args.Row > -1))
		{
			MessageBox.Show("got a record"); 
		}
		else { 
			MessageBox.Show("no record"); 
		} 
	}

And now I get the popup message of “no record”. So it’s progress! But I’m not sure why I’m not getting any record.

What is Transfer Order Workbench I don’t have that screen.

2 Likes

It’s also called Transfer Order Suggestions. It’s found inside Transfer Order Entry > Actions.
It looks like this:

We use TO’s all the time, but have never used that workbench.

And now that I look at the help topic on it, I see it is for MRP generated suggestions. And since we don’t use MRP, I can’t test this.

You might not even need to use an epiViewNotification function just grab the data from the view when the button is clicked (after you check that it’s not empty)

This is exactly what I want, but I don’t know how or the syntax to do that. =(

We don’t generate TO Suggestions, so I had to test this on just a TO Order Detail, but the concept should work.

In the Button click handler:

private void btnTest_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		EpiDataView dtlView = (EpiDataView)(oTrans.EpiDataViews["detailView"]);
		string dtlSysRowID = dtlView.dataView[dtlView.Row]["SysRowID"].ToString();
		MessageBox.Show(dtlSysRowID);
	}

That doesn’t check for an empty dataview. It is left as an exercise for the student to figure out how to handle that. :wink:

edit

The above fetches the SysRowID of the “detailView”, and not the SysRowID for the Part referenced on the detailView Row.

Looks like the views on that screen are
newSugView
chgSugView

You need to use that view instead of the partView I don’t think that one gets populated.

the partView EpiDataView comes from the partAdapter.PartList and not from the suggestion views. It is only populated when you click the part button and search for something.

Jose - Since data views aren’t always an exact copy of a tables data, does the the SysRowID of a dataview really mean anything outside of the context of this isolated session?

It seems like the OP will need to use PartNum from the view to query the part table in order to fetch that part’s SysRowID.

Nice catch @ckrusen

Right so the SysRowID in the newSugView or chgSugView would be the SysRowID of the individual suggestion and not that of the related part.

If he wants the SysRowID of the part he probably first has to add an FKV (two actually) Foreign Key Views that basically bring in a new PartdataView for each of the above views.

Then he could use those views instead.

So

  1. Add FKV for Part matching to newSugView.PartNum call it newSugPartView
  2. Add FKV for Part matching to chgSugView.PartNum call it chgSugPartView

Then you can use

var newSugPartView = oTrans.Factory("newSugPartView");
string sysRowID = newSugPartView.dataView[newSugPartView.Row]["SysRowID"].ToString();
// or 
var newSugPartView = oTrans.Factory("chgSugPartView");
string sysRowID = chgSugPartView.dataView[chgSugPartView.Row]["SysRowID"].ToString();

Depending on which one he wants to pass along to the buggon.

HTH

Jose was correct in that I needed to get the correct data view switching to the newSugView got me data! However Calvin is also correct, the SysRowID seems to be the SysRowID of the suggestion, not the part which is what I’m really after.

So with your help I’m on the right path. Given the sys row id of the suggestion, I wonder how I can fetch the sysrowId of the part from the part table.

See above you need a foreign key view.

With jose’s FKV instructions you can get something like:

And that partSysRowID matches the part table’s value

image

Yes with your powers combined @Ckrusen @josecgomez it works! I had to lookup in the customization manual how to do a FKV but once I got it, Jose’s code suggestion worked pretty much as is.

The buttons launch to the page correctly with the correct part SRID and changing to a new suggestion part still works too.

Thank you for the protips. Today was a good day :musical_note:.

1 Like

What happens if you press the button with no suggestion loaded?

Might want to throw in a .HasRow on on the dataview before trying to read it. Like:

var newSugPartView = oTrans.Factory("newSugPartView");
if(newSugPartView.HasRow){
    string sysRowID = newSugPartView.dataView[newSugPartView.Row]["SysRowID"].ToString();
    Process.Start(....);
    }
1 Like

Yes you were correct about that. I added the guard clause as you suggested and that worked. Nice catch!