Running some VB code when saving a record (Partially Solved)

So i was successful to get the info saved in the JobHead with the following
code

But i still face 2 problems :

1) when i try to get the date from the Jobhead on load i get the error
"object reference not set to an instance of an object" on the following line
of code :
Dim dsJobEntry as Epicor.Mfg.BO.JobEntryDataSet =
m_boJobEntry.GetByID(edvClose.dataView.Table.Rows(edvClose.Row)("JobNum"))

2) The update works for character or date fields but not for checkbox and i
dont get why?

Thanks for the help

Here is my full code on the job closing:


'//**************************************************
'// Custom VB.NET code for JobClosingForm
'// Created: 03/14/2011 17:47:27
'//**************************************************
Imports System
Imports System.Data
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.ComponentModel
Imports Microsoft.VisualBasic
Imports Epicor.Mfg.UI
Imports Epicor.Mfg.UI.FrameWork
Imports Epicor.Mfg.UI.ExtendedProps
Imports Epicor.Mfg.UI.FormFunctions
Imports Epicor.Mfg.UI.Customization
Imports Epicor.Mfg.UI.Adapters
Imports Epicor.Mfg.UI.Searches
Imports Epicor.Mfg.BO


Module Script


'// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added
Module Level Variables' Comments! **
'// Begin Wizard Added Module Level Variables **

Private WithEvents edvClose As EpiDataView
Private WithEvents edvBpmData As EpiDataView
'// End Wizard Added Module Level Variables **

Private m_boJobEntry as Epicor.Mfg.BO.JobEntry

'// Add Custom Module Level Variables Here **

Sub InitializeCustomCode()


'// ** Wizard Insert Location - Do not delete 'Begin/End Wizard
Added Variable Initialization' lines **
'// Begin Wizard Added Variable Initialization
edvClose = CType(oTrans.EpiDataViews("Close"), EpiDataView)
edvBpmData = CType(oTrans.EpiDataViews("CallContextBpmData"),
EpiDataView)

AddHandler edvClose.EpiViewNotification, AddressOf
edvClose_EpiViewNotification
AddHandler BpmData_Column.ColumnChanged, AddressOf
BpmData_AfterFieldChange
'// End Wizard Added Variable Initialization
'// Begin Wizard Added Custom Method Calls

m_boJobEntry = new
Epicor.Mfg.BO.JobEntry(oTrans.Session.ConnectionPool)

'// End Wizard Added Custom Method Calls

End Sub



Sub DestroyCustomCode()


'// ** Wizard Insert Location - Do not delete 'Begin/End Wizard
Added Object Disposal' lines **
'// Begin Wizard Added Object Disposal

RemoveHandler edvClose.EpiViewNotification, AddressOf
edvClose_EpiViewNotification
edvBpmData = Nothing
RemoveHandler BpmData_Column.ColumnChanged, AddressOf
BpmData_AfterFieldChange
edvClose = Nothing
'// End Wizard Added Object Disposal
'// Begin Custom Code Disposal

m_boJobEntry = nothing

'// End Custom Code Disposal

End Sub




Private Sub BpmData_AfterFieldChange(ByVal sender As Object, ByVal args
As DataColumnChangeEventArgs)
'** Argument Properties and Uses **
'args.Row("[FieldName]")
'args.Column, args.ProposedValue, args.Row
'Add Event Handler Code
Try
Select Case args.Column.ColumnName

Case "Character01"
SetStringValue("JobHead", args.Column.ColumnName,
args.Row(args.Column.ColumnName))
Case "CheckBox01"
SetStringValue("JobHead", args.Column.ColumnName,
args.Row(args.Column.ColumnName))
Case "Date01"
SetStringValue("JobHead", args.Column.ColumnName,
args.Row(args.Column.ColumnName))
Case "CheckBox02"
SetStringValue("JobHead", args.Column.ColumnName,
args.Row(args.Column.ColumnName))
Case "Date02"
SetStringValue("JobHead", args.Column.ColumnName,
args.Row(args.Column.ColumnName))


Case Else

End Select
catch ex as Exception
MessageBox.Show("JobEntry error: " & ex.Message)
end try

End Sub



Private Sub SetStringValue(ByVal table as String, ByVal columnName as
String, ByVal value as String)
try
Dim dsJobEntry as Epicor.Mfg.BO.JobEntryDataSet =
m_boJobEntry.GetByID(edvClose.dataView.Table.Rows(edvClose.Row)("JobNum"))
Dim row as DataRow
Dim bUpdate as Boolean = False
for each row in dsJobEntry.Tables(table).Rows
REM if (row(columnName) <> value ) then
row(columnName) = value
row("RowMod") = "U"
bUpdate = True
REM end if
next
if ( bUpdate ) then
m_boJobEntry.Update(dsJobEntry)
REM oTrans.Refresh()
end if
catch ex as Exception
MessageBox.Show("SetStringValue error: " & ex.Message)
end try
End Sub


Private Sub GetValue()
try
Dim dsJobEntry as Epicor.Mfg.BO.JobEntryDataSet =
m_boJobEntry.GetByID(edvClose.dataView.Table.Rows(edvClose.Row)("JobNum"))
Dim row as DataRow
for each row in dsJobEntry.Tables("JobEntry").Rows


edvBpmData.dataView.Table.Rows(edvBpmData.Row)("Character01") =
row("Character01")

edvBpmData.dataView.Table.Rows(edvBpmData.Row)("CheckBox01") =
row("CheckBox01")
edvBpmData.dataView.Table.Rows(edvBpmData.Row)("Date01")
= row("Date01")

edvBpmData.dataView.Table.Rows(edvBpmData.Row)("CheckBox02") =
row("CheckBox02")
edvBpmData.dataView.Table.Rows(edvBpmData.Row)("Date02")
=
row("Date02")


next

catch ex as Exception
MessageBox.Show("GetValue error: " & ex.Message)
end try
End Sub




Private Sub edvClose_EpiViewNotification(ByVal view As EpiDataView,
ByVal args As EpiNotifyArgs)
'** 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) Then
If (args.Row > -1) Then
GetValue()
End If
End If

End Sub


End Module


On Wed, Sep 7, 2011 at 11:27 AM, Ephraim Feldman <effgroups@...>wrote:

> That was my first thought to make it on the job entry
> But the problem with using the jobentry is that i cant make changes once
> the job has been engineered.
> I just need to update some custom fields
> maybe there is a way to allow that ?
>
>
>
>
> On Wed, Sep 7, 2011 at 11:15 AM, Brian Roberts <broberts@...>wrote:
>
>> **
>>
>>
>> Do you have to start with the job closing screen? If you're just
>> updating JobHead, then customize Job Entry like crazy, hiding everything
>> you don't want, and then you've got the normal Update method. Add your
>> customization as a new menu item.
>>
>>
>> Brian.
>>
>> -----Original Message-----
>> From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
>> Of Ephraim Feldman
>> Sent: Wednesday, September 07, 2011 11:03 AM
>>
>> To: vantage@yahoogroups.com
>> Subject: Re: [Vantage] Running some VB code when saving a record
>>
>> No the JobMt and JobOper doesnt help me and i cant use the complete
>> because
>> i want basically have a flag that the order was picked and where the
>> staging
>> location is
>>
>> On Wed, Sep 7, 2011 at 10:59 AM, Brian Roberts <broberts@...>
>> wrote:
>>
>> > **
>> >
>> >
>> > There are a couple of OnChange methods (in the JobClosing BO). Can you
>> > use the completed flag? I know the JobMtl & JobOper tables have the UD
>> > fields available for display on that form, not sure if they'll be any
>> > help to you.
>> >
>> > Brian.
>> >
>> > -----Original Message-----
>> > From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On
>> Behalf
>> > Of Ephraim Feldman
>> > Sent: Wednesday, September 07, 2011 10:45 AM
>> >
>> > To: vantage@yahoogroups.com
>> > Subject: Re: [Vantage] Running some VB code when saving a record
>> >
>> > Yes theere is a method but only when you actually Close the job but it
>> > doesnt run otherwise.
>> > Also i dont have custom fields to store info for the BPM to run on.
>> >
>> > Ephraim
>> >
>> > On Wed, Sep 7, 2011 at 10:26 AM, Waffqle <waffqle@...> wrote:
>> >
>> > > **
>> > >
>> > >
>> > > I'm not an expert on Job Closing, but surely it must call SOME
>> method?
>> > Is
>> > > Epicor really bypassing the whole BL layer?
>> > >
>> > >
>> > > On Wed, Sep 7, 2011 at 10:04 AM, <effgroups@...> wrote:
>> > >
>> > > > I can't run a BPM on job closing since there are no custom fields
>> to
>> > use
>> > > in
>> > > > that program.
>> > > > The job closing program is a different kind of program since it
>> > doesn't
>> > > > have a dataset based on a actual table so there are no custom
>> fields
>> > and
>> > > > that's why I used controls not linked to a field and try to update
>> > the
>> > > > jobhead with code.
>> > > >
>> > > > Ephraim
>> > > > Ephraim Feldman
>> > > >
>> > > > -----Original Message-----
>> > > > From: Ted Koch <tkoch77@...>
>> > > > Sender: vantage@yahoogroups.com
>> > > > Date: Wed, 7 Sep 2011 06:44:56
>> > > > To: vantage@yahoogroups.com<vantage@yahoogroups.com>
>> > > > Reply-To: vantage@yahoogroups.com
>> > > > Subject: Re: [Vantage] Running some VB code when saving a record
>> > > >
>> > > > Did you try using a BPM to make these fields mandatory? That might
>> > work
>> > > > better if that's what you are trying to accomplish.
>> > > >
>> > > >
>> > > >
>> > > > ________________________________
>> > > > From: "effgroups@..." <effgroups@...>
>> > > > To: vantage@yahoogroups.com
>> > > > Sent: Wednesday, September 7, 2011 9:40 AM
>> > > > Subject: Re: [Vantage] Running some VB code when saving a record
>> > > >
>> > > > Thanks Tod for the quick answer.
>> > > >
>> > > > The problem is that I want to run the code in the job closing
>> > program.
>> > > > There is only one adapter there that is when you close the job but
>> I
>> > > added
>> > > > a few field that I want the user to fill in even they don't close
>> > the
>> > > job.
>> > > >
>> > > > Maybe my only option is to run it after field change?
>> > > >
>> > > > Ephraim
>> > > > Ephraim Feldman
>> > > >
>> > > > -----Original Message-----
>> > > > From: Ted Koch <tkoch77@...>
>> > > > Sender: vantage@yahoogroups.com
>> > > > Date: Wed, 7 Sep 2011 05:12:53
>> > > > To: vantage@yahoogroups.com<vantage@yahoogroups.com>
>> > > > Reply-To: vantage@yahoogroups.com
>> > > > Subject: Re: [Vantage] Running some VB code when saving a record
>> > > >
>> > > > Ephraim,
>> > > >
>> > > > You could accomplish by using this code. This will run the code
>> > after the
>> > > > Update method of the Job Adapter has been called. If you want
>> before
>> > it
>> > > > saves use BeforeAdapterMethod.
>> > > >
>> > > >
>> > > > Private Sub oTrans_jobAdapter_AfterAdapterMethod(ByVal sender As
>> > Object,
>> > > > ByVal args As AfterAdapterMethodArgs)
>> > > > ' ** Argument Properties and Uses **
>> > > > ' ** args.MethodName **
>> > > > ' ** Add Event Handler Code **
>> > > >
>> > > > ' ** Use MessageBox to find adapter method name
>> > > > ' EpiMessageBox.Show(args.MethodName)
>> > > > Select Case args.MethodName
>> > > >
>> > > > Case "Update"
>> > > >
>> > > > End Select
>> > > >
>> > > > End Sub
>> > > >
>> > > > Hope that helps
>> > > >
>> > > > Ted
>> > > >
>> > > >
>> > > >
>> > > > ________________________________
>> > > > From: Ephraim Feldman <effgroups@...>
>> > > > To: vantage@yahoogroups.com
>> > > > Sent: Wednesday, September 7, 2011 12:19 AM
>> > > > Subject: [Vantage] Running some VB code when saving a record
>> > > >
>> > > > Hi all
>> > > >
>> > > > I created a customization that connect to the JobEntry adapter and
>> > > updates
>> > > > some custom fields and i want it to run when the user saves the
>> > record
>> > > how
>> > > > can i accomplish that?
>> > > >
>> > > >
>> > > > here is my code:
>> > > >
>> > > > Private Sub JobInfo(ByVal Mode As String)
>> > > >
>> > > > 'Declare and Initialize EpiDataView Variables
>> > > > Dim edvClose As EpiDataView =
>> > > > CType(oTrans.EpiDataViews("Close"),EpiDataView)
>> > > >
>> > > > 'Check if valid EpiDataView Row(s) are selected
>> > > > If (edvClose.Row < 0) Then
>> > > > Exit Sub
>> > > > End If
>> > > >
>> > > > 'Create instance of Adapter
>> > > > Dim adapterJobEntry As JobEntryAdapter = New
>> > > > JobEntryAdapter(oTrans)
>> > > > adapterJobEntry.BOConnect()
>> > > >
>> > > > 'Declare and Initialize Variables
>> > > > Dim jobNum As String =
>> > > > CType(edvClose.dataView(edvClose.Row)("JobNum"),String)
>> > > >
>> > > > 'Call Adapter method
>> > > > Dim result As Boolean = adapterJobEntry.GetByID(jobNum)
>> > > >
>> > > > Try
>> > > >
>> > > > Dim MyTXTStage as epiTextBox
>> > > > MyTXTStage =
>> > > >
>> > > >
>> > >
>> >
>> CType(csm.GetNativeControlReference("7b45bf03-0f29-4324-bbaa-834bab503d2
>> > a"),EpiTextBox)
>> > > >
>> > > >
>> > > > Dim MyCHKPick as epiCheckBox
>> > > > MyCHKPick =
>> > > >
>> > > >
>> > >
>> >
>> CType(csm.GetNativeControlReference("36009aeb-c55e-4129-b0a2-129e3faf10e
>> > e"),EpiCheckBox)
>> > > >
>> > > > Dim MyDatePick as epiDateTimeEditor
>> > > > MyDatePick =
>> > > >
>> > > >
>> > >
>> >
>> CType(csm.GetNativeControlReference("ee001405-b7fd-41aa-a25c-536f01910fa
>> > 1"),EpiDateTimeEditor)
>> > > >
>> > > >
>> > > > Dim MyCHKWip as epiCheckBox
>> > > > MyCHKWip =
>> > > >
>> > > >
>> > >
>> >
>> CType(csm.GetNativeControlReference("4193e051-a401-4076-a3e9-13678eb9d55
>> > 7"),EpiCheckBox)
>> > > >
>> > > > Dim MyDateWip as epiDateTimeEditor
>> > > > MyDateWip =
>> > > >
>> > > >
>> > >
>> >
>> CType(csm.GetNativeControlReference("b3b29a66-ec2c-43c7-bcac-cd408dfc005
>> > a"),EpiDateTimeEditor)
>> > > >
>> > > >
>> > > > If Mode = "Update" Then
>> > > >
>> > > > adapterJobEntry.JobEntryData.Tables("JobHead").Rows(0).BeginEdit()
>> > > >
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("Character01" ) =
>> > > > MyTXTStage.Text
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("CheckBox01" ) =
>> > > > MyCHKPick.Checked
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("Date01" ) =
>> > > > MyDatePick.Value
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("CheckBox02" ) =
>> > > > MyCHKWip.Checked
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("Date02" ) =
>> > > > MyDateWip.Value
>> > > >
>> > > >
>> > > > adapterJobEntry.JobEntryData.Tables("JobHead").Rows(0).EndEdit()
>> > > > adapterJobEntry.Update()
>> > > >
>> > > > Else If Mode = "Get" Then
>> > > > MyTXTStage.Text =
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("Character01" )
>> > > > MyCHKPick.Checked =
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("CheckBox01" )
>> > > > MyDatePick.Value =
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("Date01" )
>> > > > MyCHKWip.Checked =
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("CheckBox02" )
>> > > > MyDateWip.Value =
>> > > > adapterJobEntry.JobEntryData.JobHead(0)("Date02" )
>> > > > End If
>> > > >
>> > > > Catch e As Exception
>> > > >
>> > > >
>> > > > End Try
>> > > >
>> > > >
>> > > >
>> > > > 'Cleanup Adapter Reference
>> > > > adapterJobEntry.Dispose()
>> > > > adapterJobEntry = Nothing
>> > > >
>> > > > End Sub
>> > > >
>> > > >
>> > > > [Non-text portions of this message have been removed]
>> > > >
>> > > >
>> > > >
>> > > > ------------------------------------
>> > > >
>> > > > Useful links for the Yahoo!Groups Vantage Board are: ( Note: You
>> > must
>> > > have
>> > > > already linked your email address to a yahoo id to enable access.
>> )
>> > > > (1) To access the Files Section of our Yahoo!Group for Report
>> > Builder and
>> > > > Crystal Reports and other 'goodies', please goto:
>> > > > http://groups.yahoo.com/group/vantage/files/.
>> > > > (2) To search through old msg's goto:
>> > > > http://groups.yahoo.com/group/vantage/messages
>> > > > (3) To view links to Vendors that provide Vantage services goto:
>> > > > http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
>> > > >
>> > > >
>> > > >
>> > > > [Non-text portions of this message have been removed]
>> > > >
>> > > >
>> > > >
>> > > >
>> > > > [Non-text portions of this message have been removed]
>> > > >
>> > > >
>> > > >
>> > > > ------------------------------------
>> > > >
>> > > > Useful links for the Yahoo!Groups Vantage Board are: ( Note: You
>> > must
>> > > have
>> > > > already linked your email address to a yahoo id to enable access.
>> )
>> > > > (1) To access the Files Section of our Yahoo!Group for Report
>> > Builder and
>> > > > Crystal Reports and other 'goodies', please goto:
>> > > > http://groups.yahoo.com/group/vantage/files/.
>> > > > (2) To search through old msg's goto:
>> > > > http://groups.yahoo.com/group/vantage/messages
>> > > > (3) To view links to Vendors that provide Vantage services goto:
>> > > > http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
>> > > >
>> > > >
>> > > >
>> > > > [Non-text portions of this message have been removed]
>> > > >
>> > > >
>> > > >
>> > > >
>> > > > [Non-text portions of this message have been removed]
>> > > >
>> > > >
>> > > >
>> > > > ------------------------------------
>> > > >
>> > > > Useful links for the Yahoo!Groups Vantage Board are: ( Note: You
>> > must
>> > > have
>> > > > already linked your email address to a yahoo id to enable access.
>> )
>> > > > (1) To access the Files Section of our Yahoo!Group for Report
>> > Builder and
>> > > > Crystal Reports and other 'goodies', please goto:
>> > > > http://groups.yahoo.com/group/vantage/files/.
>> > > > (2) To search through old msg's goto:
>> > > > http://groups.yahoo.com/group/vantage/messages
>> > > > (3) To view links to Vendors that provide Vantage services goto:
>> > > > http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
>> > > >
>> > > >
>> > > >
>> > > >
>> > >
>> > > --
>> > > *Waffqle Driggers*
>> > > *High End Dev, System Design, Profit Drinking
>> > > *
>> > > *:: 904.962.2887*
>> > > *:: waffqle@...*
>> > > *:: NO FAXES*
>> > >
>> > > *
>> > >
>> > >
>> > > *
>> > >
>> > > [Non-text portions of this message have been removed]
>> > >
>> > >
>> > >
>> >
>> > [Non-text portions of this message have been removed]
>> >
>> > ------------------------------------
>> >
>> > Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
>> > have already linked your email address to a yahoo id to enable access.
>> )
>> > (1) To access the Files Section of our Yahoo!Group for Report Builder
>> > and Crystal Reports and other 'goodies', please goto:
>> > http://groups.yahoo.com/group/vantage/files/.
>> > (2) To search through old msg's goto:
>> > http://groups.yahoo.com/group/vantage/messages
>> > (3) To view links to Vendors that provide Vantage services goto:
>> > http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
>> >
>> >
>> >
>>
>> [Non-text portions of this message have been removed]
>>
>> ------------------------------------
>>
>> Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
>> have already linked your email address to a yahoo id to enable access. )
>> (1) To access the Files Section of our Yahoo!Group for Report Builder
>> and Crystal Reports and other 'goodies', please goto:
>> http://groups.yahoo.com/group/vantage/files/.
>> (2) To search through old msg's goto:
>> http://groups.yahoo.com/group/vantage/messages
>> (3) To view links to Vendors that provide Vantage services goto:
>> http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
>>
>>
>>
>
>


[Non-text portions of this message have been removed]