Page 1 of 1

Using a Business logic Object inside a scheduled plugin

PostPosted: Tue Jul 04, 2017 12:18 pm
by SBarnes
How can you use a Business Logic object inside the scheduled plugin?

For example

Code: Select all
JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess batch = Plugin.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess>(null);


produces an exception?

I would imagine this would produce the same error for any CreateBusinessLogic call?

Re: Using a Business logic Object inside a scheduled plugin

PostPosted: Tue Jul 04, 2017 2:03 pm
by Mike.Sheen
You shouldn't get any exceptions.

What is the exception, exactly?

Re: Using a Business logic Object inside a scheduled plugin

PostPosted: Tue Jul 04, 2017 2:22 pm
by SBarnes
Hi Mike

here is the stack trace

Code: Select all
System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=JiwaSales
  StackTrace:
       at JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess.ReadUserSettings()
       at JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess.Setup()
       at JiwaFinancials.Jiwa.JiwaApplication.BusinessLogicFactory.CreateBusinessLogic[BusinessLogicType](IJiwaForm Client)
       at ScheduledExecutionPlugin.Execute(Plugin Plugin, Schedule Schedule) in c:\ProgramData\Jiwa Financials\Jiwa 7\7.0.182\SYSTEM\WIN-EIBG30HI5AK\Cassons\Plugins\Admin\Compile\Attkey Debtor Term Deals\Attkey Debtor Term Deals.cs:line 259
       at JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin.RunScheduledExecutionPluginExecute(Schedule Schedule)
       at JiwaFinancials.Jiwa.JiwaPluginSchedulerService.JiwaPluginSchedulerService.ProcessPlugins()
  InnerException:


Interestingly the following in the same plugin works fine

Code: Select all
JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder workorder = Plugin.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder>(null);   


If you instantiate the batch object without the factory that works you can even assign a manager but as soon as you call setup to instantiate the ProcessCandidates Collection you get the same error.

Re: Using a Business logic Object inside a scheduled plugin  Topic is solved

PostPosted: Tue Jul 04, 2017 3:00 pm
by Mike.Sheen
That's a bug - and it's not isolated to within the plugin scheduler - any code trying to create a batch process business logic using our factory and passing null for the form will get that error.

Logged as DEV-6053.

Your work-around is to provide a form to the BusinessLogicFactory.

e.g.:

Code: Select all
var form = Plugin.Manager.FormFactory.CreateForm<JiwaFinancials.Jiwa.JiwaSalesUI.BatchProcessing.BatchProcess>(); // create a form to work-around DEV-6053
JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess batch = Plugin.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.BatchProcessing.BatchProcess>(form);
batch.Client = null;

Re: Using a Business logic Object inside a scheduled plugin

PostPosted: Tue Jul 04, 2017 3:11 pm
by SBarnes
HI Mike,

Thanks that works, one quick question, can the plugin scheduler print the reports if the properties are set properly, as I know it can be a real issue inside IIS if you try it with network printers i.e. network printers only exist if the user is logged in, just not sure about a windows service?

Re: Using a Business logic Object inside a scheduled plugin

PostPosted: Tue Jul 04, 2017 3:19 pm
by Mike.Sheen
If the service is running under user credentials, and not local system, then yes - it will be able to print.

Re: Using a Business logic Object inside a scheduled plugin

PostPosted: Tue Jul 04, 2017 3:22 pm
by SBarnes
As always thanks.