Debugging Plugin Code Line By Line  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Debugging Plugin Code Line By Line

Postby sagharfrancis » Thu Jun 16, 2022 3:11 pm

I am new to Jiwa Plugin development/customization. I saw a guide on this forum Titled "Developing plugins for Jiwa 7 using Visual Studio 2012" this guide seems outdated. Is there any newly updated guide on How to run the plugin code on the visual studio to debug the code line by line?
sagharfrancis
I'm new here
I'm new here
 
Posts: 7
Joined: Wed Jun 15, 2022 4:56 am

Re: Debugging Plugin Code Line By Line

Postby Scott.Pearce » Thu Jun 16, 2022 4:15 pm

Place the line of code (c#):

Code: Select all
System.Diagnostics.Debugger.Launch();


in the plugin. Log out and back into Jiwa so the plugin gets recompiled. Perform an action in Jiwa that you know will cause the above line of code to be hit. A window will appear asking which debugger to use (ie. VS2022).
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Debugging Plugin Code Line By Line

Postby sagharfrancis » Thu Jun 16, 2022 4:28 pm

I have some plugins developed in vb.net. Please share the guide to running the plugin code in Visual Studio.
sagharfrancis
I'm new here
I'm new here
 
Posts: 7
Joined: Wed Jun 15, 2022 4:56 am

Re: Debugging Plugin Code Line By Line

Postby Scott.Pearce » Thu Jun 16, 2022 5:19 pm

OK. Se let's take a look at a standard VB plugin that is enabled in the demonstration database.

Assumptions:
Jiwa 7.2.1 SR11 is installed.
A fresh copy of the Jiwa demonstration data has been created.
At least one debugger is installed. This example will use Visual Studio 2022.

Log into the demo data:
Login.png
Login.png (14.64 KiB) Viewed 563 times


Load Plugin Maintenance from "System Settings->Plugins->Plugin Maintenance":
Plugin Maintenance.png


Use the "Search" to find the "Move Lines to New Order" plugin:
Move Lines Plugin.png


Now, this particular plugin adds a button to the "Utilities" tab on the menu ribbon of the sales order entry screen ("Sales->Order Entry" from the menu) with the caption "Move lines to a new order". I know this by reading the plugin description. But I can also infer this. Look at the "Forms" tab of the plugin - there is an entry for "Sales Orders". This means that this plugin will load when the sales order entry form is loaded. Now look at the "Code" tab of the plugin and examine the "Setup" function in the "FormPlugin" class - here we see that a button is created and added to the ribbon menu, and a handler added to fire when the button is clicked.

Let's say we want to be able to step through the code of this plugin right from the start. Important point - for any form that appears on the "Forms" tab of the plugin, the "SetupBeforeHandlers" function of the "FormPlugin" class is called when that form is loaded by the user. This is the very earliest starting point of the plugin. Following that call, a call into "Setup" of the "FormPlugin" class is made. I am going to insert the debugger launch code into the "SetupBeforeHandlers" function of the "FormPlugin" class:

Code: Select all
System.Diagnostics.Debugger.Launch()


Debugger Launch Code.png


Now click the "Compile" button on the code tab toolbar and ensure no compile errors occur. Save the plugin, log out and back into Jiwa so that your code change is compiled. Now whenever you launch the sales order entry form, you will be presented with this dialog:
Choose Debugger.png


Select the debugger you wish to use via the dialog and then click OK. Your debugger will now load and be waiting to step from the "System.Diagnostics.Debugger.Launch()" line of code we inserted:
Debugging.png


I'm now in a normal Visual Studio development environment. I'm going to set a breakpoint in the "Setup" function, and the press "Continue". Now I've hit my breakpoint:
Debugging 3.png


From here I can step through the code, examine variable values, etc. just as if I was running the plugin code natively in the IDE. I hope this gets you started in the wonderful world of Jiwa plugin debugging.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Debugging Plugin Code Line By Line

Postby sagharfrancis » Thu Jun 16, 2022 7:34 pm

Scott.Pearce wrote:OK. Se let's take a look at a standard VB plugin that is enabled in the demonstration database.

Assumptions:
Jiwa 7.2.1 SR11 is installed.
A fresh copy of the Jiwa demonstration data has been created.
At least one debugger is installed. This example will use Visual Studio 2022.

Log into the demo data:
Login.png


Load Plugin Maintenance from "System Settings->Plugins->Plugin Maintenance":
Plugin Maintenance.png


Use the "Search" to find the "Move Lines to New Order" plugin:
Move Lines Plugin.png


Now, this particular plugin adds a button to the "Utilities" tab on the menu ribbon of the sales order entry screen ("Sales->Order Entry" from the menu) with the caption "Move lines to a new order". I know this by reading the plugin description. But I can also infer this. Look at the "Forms" tab of the plugin - there is an entry for "Sales Orders". This means that this plugin will load when the sales order entry form is loaded. Now look at the "Code" tab of the plugin and examine the "Setup" function in the "FormPlugin" class - here we see that a button is created and added to the ribbon menu, and a handler added to fire when the button is clicked.

Let's say we want to be able to step through the code of this plugin right from the start. Important point - for any form that appears on the "Forms" tab of the plugin, the "SetupBeforeHandlers" function of the "FormPlugin" class is called when that form is loaded by the user. This is the very earliest starting point of the plugin. Following that call, a call into "Setup" of the "FormPlugin" class is made. I am going to insert the debugger launch code into the "SetupBeforeHandlers" function of the "FormPlugin" class:

Code: Select all
System.Diagnostics.Debugger.Launch()


Debugger Launch Code.png


Now click the "Compile" button on the code tab toolbar and ensure no compile errors occur. Save the plugin, log out and back into Jiwa so that your code change is compiled. Now whenever you launch the sales order entry form, you will be presented with this dialog:
Choose Debugger.png


Select the debugger you wish to use via the dialog and then click OK. Your debugger will now load and be waiting to step from the "System.Diagnostics.Debugger.Launch()" line of code we inserted:
Debugging.png


I'm now in a normal Visual Studio development environment. I'm going to set a breakpoint in the "Setup" function, and the press "Continue". Now I've hit my breakpoint:
Debugging 3.png


From here I can step through the code, examine variable values, etc. just as if I was running the plugin code natively in the IDE. I hope this gets you started in the wonderful world of Jiwa plugin debugging.


Thanks for your reply. This is really helpful but why there is no any documentation or tutorial regarding these types of things.
sagharfrancis
I'm new here
I'm new here
 
Posts: 7
Joined: Wed Jun 15, 2022 4:56 am

Re: Debugging Plugin Code Line By Line  Topic is solved

Postby SBarnes » Thu Jun 16, 2022 10:00 pm

Thanks for your reply. This is really helpful but why there is no any documentation or tutorial regarding these types of things.


It is documented see the link below, what Scott has kindly given instructions on is a Microsoft's .net framework feature that is not just particular to Jiwa alone.

Any documentation regarding Jiwa is here https://docs.jiwa.com.au/ but not everything can be documented and put into a tutorial.

To be honest the best source of finding answers that I have seen over my many years of working with Jiwa is this forum itself, where if the question hasn't already been asked, you can ask and you will get an answer in a reasonably short period of time.

https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Debugging Plugin Code Line By Line

Postby Mike.Sheen » Fri Jun 17, 2022 12:16 am

sagharfrancis wrote:Thanks for your reply. This is really helpful but why there is no any documentation or tutorial regarding these types of things.


Because we are a small company, and cannot document everything and we expect developers to at least have a rudimentary knowledge of .NET programming and debugging.

You also need to understand we sell and support the product, not the development / customisation aspects. We offer what support we can to developers, for free, on these forums - but we are under no obligation to do so.

Are you looking for answers, or are you wanting to find someone to blame. We only have answers here.
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


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 9 guests

cron