Can't access oTrans in code

Hi All,

E9.05.702A

I am creating a UI customization for the Time and Materials Invoice Review screen in the Project Management module.
I’ve worked with the oTrans object many times before in other screens but in this case, I cannot access it outside of InitializeCustomCode() and DestroyCustomCode() methods.

I created a method with a signature of: private static void deleteTMInvoiceLines(string strLineType)

If I were to just include “oTrans.Refresh();” in this method and try to test the code, I get the following error message:
Error: CS0120 - line 103 (232) - An object reference is required for the nonstatic field, method, or property ‘Script.oTrans’

I haven’t seen this before and looking back on other customizations, I didn’t have to do anything to gain access to oTrans but it could be that I’m just missing something.

Any ideas on why I cannot access oTrans in this case?

JOE ROJAS
Epicor Applications Manager
VENTION MEDICAL + DESIGN & DEVELOPMENT
Advancing Your Innovations For Health

261 Cedar Hill Street | Marlborough, MA 01752
DIRECT: 508.597.1392 x1625 | MOBILE: 774.826.9245
EMAIL: JoRojas@ventionmedical.commailto:JoRojas@ventionmedical.com | WEB: ventionmedical.com http://www.ventionmedical.com/

THINK QUALITY. BE QUALITY. GO BEYOND.

This communication may contain information that is confidential, proprietary or exempt from disclosure, and is intended only for the use of the individual and/or entity it is addressed to. If you are not the intended recipient, please note that any other dissemination, distribution, use or copying of this communication is strictly prohibited. If you have received this message in error, please notify the sender immediately by telephone or by return e-mail, and delete this information from your computer.

Don’t make your method static
private void deleteTMInvoiceLines()

Thanks Jose

I tried that and it didn’t work. Same error.
private void deleteTMInvoiceLines(string strLineType)

JOE ROJAS
Epicor Applications Manager
VENTION MEDICAL + DESIGN & DEVELOPMENT
DIRECT: 508.597.1392 x1625 | MOBILE: 774.826.9245

Share your whole Customization here…

Ignore my last reply.
I jumped the gun, when I remove “static” I got a new error:
Error: CS0120 - line 85 (214) - An object reference is required for the nonstatic field, method, or property ‘Script.deleteTMInvoiceLines(string)’

This error on a line that is called my method. The calling line is:
deleteTMInvoiceLines(“LBR”);

JOE ROJAS
Epicor Applications Manager
VENTION MEDICAL + DESIGN & DEVELOPMENT
DIRECT: 508.597.1392 x1625 | MOBILE: 774.826.9245

The whole customization is below. It’s not finished but I don’t think that will matter.
In the end I had to remove “static” from both:
private static void deleteAllMaterialLines(Object sender, ToolClickEventArgs e)
private static void deleteAllLaborLines(Object sender, ToolClickEventArgs e)

These changes are reflected below and the code below tests without error.
I guess I’m just curious why the removal of “static” was required where all my prior examples did not.

// **************************************************
// Custom code for TMReviewForm
// Created: 2/7/2017 3:07:37 PM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;
using System.Reflection;
using Infragistics.Win;
using Infragistics.Win.UltraWinToolbars;

public class Script
{
// ** Wizard Insert Location - Do Not Remove ‘Begin/End Wizard Added Module Level Variables’ Comments! **
// Begin Wizard Added Module Level Variables **

            // End Wizard Added Module Level Variables **

            // Add Custom Module Level Variables Here **
            private static UltraToolbarsManager tools;
            private static EpiDataView edvPBGInvcDtlTC;

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

                            // End Wizard Added Variable Initialization

                            // Begin Wizard Added Custom Method Calls

                            // End Wizard Added Custom Method Calls

                            object objMenu = typeof(Epicor.Mfg.UI.App.PBGInvcReviewEntry.TMReviewForm).InvokeMember("baseToolbarsManager", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic, null, TMReviewForm, null);
                            tools = (UltraToolbarsManager)objMenu;
                            ButtonTool buttonTool1 = new ButtonTool("VMDeleteLabor");
                            ButtonTool buttonTool2 = new ButtonTool("VMDeleteMaterial");
                            tools.Tools.Add(buttonTool1);
                            tools.Tools.Add(buttonTool2);
                            PopupMenuTool pop = (PopupMenuTool)tools.Tools["ActionsMenu"]; //this is the pop up menu for the Actions menu item
                            pop.Tools.AddTool("VMDeleteLabor");
                            pop.Tools["VMDeleteLabor"].SharedProps.Caption = "Delete All Labor Lines";
                            pop.Tools["VMDeleteLabor"].SharedProps.AppearancesLarge.Appearance.Image = EpiUIImages.GetImage("Delete");
                            pop.Tools["VMDeleteLabor"].SharedProps.AppearancesSmall.Appearance.Image = EpiUIImages.GetImage("Delete");
                            pop.Tools["VMDeleteLabor"].ToolClick += deleteAllLaborLines;
                            pop.Tools.AddTool("VMDeleteMaterial");
                            pop.Tools["VMDeleteMaterial"].SharedProps.Caption = "Delete All Material Lines";
                            pop.Tools["VMDeleteMaterial"].SharedProps.AppearancesLarge.Appearance.Image = EpiUIImages.GetImage("Delete");
                            pop.Tools["VMDeleteMaterial"].SharedProps.AppearancesSmall.Appearance.Image = EpiUIImages.GetImage("Delete");
                            pop.Tools["VMDeleteMaterial"].ToolClick += deleteAllMaterialLines;

                            edvPBGInvcDtlTC = (EpiDataView)oTrans.EpiDataViews["PBGInvcDtlTC"];
            }

            public void DestroyCustomCode()
            {
                            // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
                            // Begin Wizard Added Object Disposal

                            // End Wizard Added Object Disposal

                            // Begin Custom Code Disposal
                            edvPBGInvcDtlTC = null;

                            // End Custom Code Disposal
            }

            private void deleteAllLaborLines(Object sender, ToolClickEventArgs e)
            {
                            DialogResult userAnswer;
                            userAnswer = MessageBox.Show("This will delete all labor lines on this invoice.\nDo you want to continue?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                            if (userAnswer == DialogResult.Yes)
                            {
                                            deleteTMInvoiceLines("LBR");
                            }

            }

            private void deleteAllMaterialLines(Object sender, ToolClickEventArgs e)
            {
                            DialogResult userAnswer;
                            userAnswer = MessageBox.Show("This will delete all material lines on this invoice.\nDo you want to continue?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                            if (userAnswer == DialogResult.Yes)
                            {
                                            deleteTMInvoiceLines("MTL");
                            }
            }

            private void deleteTMInvoiceLines(string strLineType)
            {
                            if (edvPBGInvcDtlTC.Row > -1)
                            {
                                            int i = edvPBGInvcDtlTC.dataView.Count - 1; //zero based index

                                            for (int j = i; j >= 0; j--)
                                            {
                                                            Application.DoEvents();
                                                            //if (edvPBGInvcDtlTC.dataView[j]["OrderNum"] == 1)
                                                            //{
                                                            //}
                                            }
                                            Cursor.Current = Cursors.Default;
                                            oTrans.Refresh();
                            }
                            else
                            {
                                            MessageBox.Show("No Invoice Lines");
                            }

            }

}

JOE ROJAS
Epicor Applications Manager
VENTION MEDICAL + DESIGN & DEVELOPMENT
DIRECT: 508.597.1392 x1625 | MOBILE: 774.826.9245

1 Like

I’ll take a guess - because I really don’t know.

The oTrans is not a static variable, it’s instanciated upon the creation of an instance of the form. I am surprised if you were ever able to access the oTrans statically ever. That is unless the static method you called them from had it passed in as a parameter which you could modify your original static method to do maybe like:

 private static void deleteTMInvoiceLines(string strLineType, EpiTransaction myoTrans)

All forms (that I’ve dealt with so far) inherit from EpiBaseForm:

public EpiBaseForm(IEpiTransaction epiTransaction)
//Later this occurs
this.oTransaction = (EpiTransaction)epiTransaction;

If there is no need to call this method outside of an instance of the form, why make it static? I only ask because I am trying to see if there is some tricks or workarounds I need to take note of.
.