Get Name of Plugin Dynamically  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Get Name of Plugin Dynamically

Postby SBarnes » Tue Feb 06, 2018 3:53 pm

Is it possible to get the name of a plugin dynamically in code so that that you can get the value and not have to hard code it to retrieve system settings values, this is mainly for Form plugins and Business Logic Plugins?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Get Name of Plugin Dynamically

Postby Mike.Sheen » Tue Feb 06, 2018 4:21 pm

Hi Stuart,

Yes!.

The Setup classes FormPlugin and BusinessLogicPlugin do have a parameter - Plugin which has a property Name which tells you which plugin the Setup method is being invoked for - usually in the Setup method you're usually adding event handlers - you just need to use a delegate to provide a handler, and then that delegate will have access to the variables / parameters within the scope of the Setup method - including the Plugin:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesOrderForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)JiwaForm;
   
   salesOrderForm.SalesOrder.CreateEnd += delegate(object sender, System.EventArgs e)
   { 
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;
      salesOrder.Manager.DisplayMessage(salesOrder.Client.Form, String.Format("This is Invoice No. '{0}' invoked from plugin '{1}'", salesOrder.InvoiceNo, Plugin.Name), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1);
   };
}   


Sample plugin for 7.1 attached.

Plugin Test plugin name access.xml
Sample Plugin
(32.18 KiB) Downloaded 88 times


Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Get Name of Plugin Dynamically

Postby Mike.Sheen » Tue Feb 06, 2018 6:21 pm

To add to this, if you're like me and don't like bundling all your logic for the handlers as delegate functions within the Setup method, create a new method with the Plugin as a parameter, and invoke that from the delegate in Setup:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesOrderForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)JiwaForm;
   
   salesOrderForm.SalesOrder.CreateEnd += delegate(object sender, System.EventArgs e)
   { 
        SalesOrder_CreateEnd(sender, e, Plugin);
   };
}

public void SalesOrder_CreateEnd(object sender, System.EventArgs e, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
      JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesOrder = (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)sender;
      salesOrder.Manager.DisplayMessage(salesOrder.Client.Form, String.Format("This is Invoice No. '{0}' invoked from plugin '{1}'", salesOrder.InvoiceNo, Plugin.Name), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information, System.Windows.Forms.MessageBoxDefaultButton.Button1);
}


This way you can still separate the logic into methods outside the Setup method, making it tidier and avoiding everything in one monolithic lump of code.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Get Name of Plugin Dynamically

Postby SBarnes » Wed Feb 07, 2018 6:58 am

Hi Mike,

Thanks for the replies, is there also an easy way to do this for other plugin types (CustomFieldPlugin, LineCustomFieldPlugin and SystemSettingPlugin)?

As I am trying to avoid hard coding this sort of thing in any type of plugin going forward.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Get Name of Plugin Dynamically  Topic is solved

Postby Mike.Sheen » Thu Feb 08, 2018 6:27 pm

Hi Stuart,

For the CustomFieldPlugin and LineCustomFieldPlugin classes, each method (FormatCell, ReadData, ButtonClicked) has a parameter CustomField which you can obtain the plugin name from :
Code: Select all
CustomField.PluginCustomField.CustomFieldCollection.Plugin.Name


For the SystemSettingPlugin, a parameter SystemSetting can be used to also get the Plugin name - which is actually the Section name of the system setting:
Code: Select all
SystemSetting.SettingCollection.Section


Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Get Name of Plugin Dynamically

Postby SBarnes » Thu Feb 08, 2018 6:45 pm

Thanks Mike.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 32 guests