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?
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…
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)
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.
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
Add FKV for Part matching to newSugView.PartNum call it newSugPartView
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.
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.
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.