Page 1 of 1

V7 plugin code for "FormObject.mRecordSave_Click()"

PostPosted: Tue Feb 10, 2015 2:38 pm
by dimuthu
Could you please tell me what is the V7 sales order plugin code for "FormObject.mRecordSave_Click()" ( I used this in 'Sales Order Read Completed ' V6 breakout code )

I tried "salesOrderForm.SaveRecord()" in ReadEnd event in the plugin. But when i open the sales order form it didn't load. When i remove this code it loaded.

Following are my code sample

Private salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm

Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
salesOrderForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
AddHandler salesOrderForm.SalesOrder.ReadEnd, AddressOf SalesOrderReadCompleted
End Sub

Public Sub SalesOrderReadCompleted(sender As Object, e As System.EventArgs)
try
' my coding
Finally
salesOrderForm.SaveRecord
End Try
End Sub

Regards
Dimuthu

Re: V7 plugin code for "FormObject.mRecordSave_Click()"

PostPosted: Wed Feb 11, 2015 8:01 am
by Scott.Pearce
Try:

Code: Select all
salesOrderForm.SalesOrder.Save

Re: V7 plugin code for "FormObject.mRecordSave_Click()"

PostPosted: Wed Feb 11, 2015 10:28 am
by dimuthu
Hi Scott,

Thanks for the reply. I tried that but same result. Order form didn't open and after sometime it throws the attached error message. When i commented that code part , form loaded.

Regards
Dimuthu

Re: V7 plugin code for "FormObject.mRecordSave_Click()"  Topic is solved

PostPosted: Wed Feb 11, 2015 11:12 am
by Scott.Pearce
Ah.

Saving causes the business logic object to re-read itself, so you are in an infinite loop:

Sales order is read -> Your code does sales order save -> this causes a sales order read -> this causes your code to do a sales order save -> and so-on forever.

You need to set a flag of some sort when your plugin does the save, so it knows not to run again for the next read. Here is what I mean:

Code: Select all
   Private salesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm

   Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      salesOrderForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
      AddHandler salesOrderForm.SalesOrder.ReadEnd, AddressOf SalesOrderReadCompleted
   End Sub

   Public Sub SalesOrderReadCompleted(sender As Object, e As System.EventArgs)
      Static pluginSave As Boolean
      
      If pluginSave Then
         Exit Sub
      End If
      
      pluginSave = True
      
      Try
      
      ' my coding
      
      salesOrderForm.SaveRecord
      
      Finally   
         pluginSave = False
      End Try
   End Sub


Note that I've had to move your SaveRecord call out of the Finally, because we don't always want it to happen.

Re: V7 plugin code for "FormObject.mRecordSave_Click()"

PostPosted: Wed Feb 11, 2015 4:48 pm
by dimuthu
Thanks Scott. It worked.

Regards
Dimuthu