strict warning: Only variables should be assigned by reference in /home/itechpros/servoyguy.com/sites/all/modules/links/links.inc on line 1434.

What are the best practices for upgrading to Servoy 5?

Servoy has documentation on the general upgrade process at http://wiki.servoy.com/display/SERV5/Upgrade+Notes

Once your application is upgraded, then you'll need to go through and start code fixes for the changes in Servoy 5.  The main issue is the JSEvent parameter changes.  Below we'll describe techniques to make this as easy as possible.

In the "Problems" tab at the bottom, you'll see listings of errors and warnings in the solution.  The first thing you'll want to do is change the filter so that you see all issues.  To do that, click the small arrow to the right of the problems tab (the arrow pointing down), and choose "Preferences".  Then uncheck the "Use marker limits" box, and choose ok to the dialog.  Now you'll see all issues without any numerical limit.

Next I like to group the issues by type, instead of severity.  To do that, choose that same arrow again, and choose Group By -> Type.  Now you can see all of the different type of errors that need to be fixed in your solution.  You can now also see a count of the issues by type.  So now you know exactly how many changes your going to need to make.  All of the JSEvent issues are of type "Event Method Problem".  These issues are placed on methods where the function is using the "arguments" array AND that function is used on an event of some kind.  If you expand out the type by clicking on the arrow, it will show you all of the issues for that type that need fixed.  So, now double click on one of the Event Method Problem type issues.  It will open up your editor, and take you to that location i the code.  However, before making any changes, I suggest following the next step...

Because you will be potentially making a lot of changes, I like to document those changes so that they are easy to find later.  We do that using Tags.  So, in Servoy, go to Preferences, and choose JavaScript->Task Tags.  Then add a new tag.  Call it something like "EWF" for Event Warning Fix (keep it short because you'll be typing this a lot).  Then say OK to the dialog, and let it rescan your workspace.

Now, lets go back to our Event Method Problem issue.  Open one of those issues back up, and lets start fixing the method.  The first thing you need to know is what type of event is calling this function (or potentially multiple events).  They way to find this out is to copy the UUID of the function.  It shows above in the comment tag like:

 

@properties={typeid:24,uuid:"e43e06c1-a7b1-439d-9aa0-235d84e7019b"}

 

So the UUID there would be e43e06c1-a7b1-439d-9aa0-235d84e7019b.  Copy that to your clipboard.  So, now choose Search->Search from the top menu, and in the Containing Text field, past in the UUID value, and do your search.  Then in the results, you'll see what forms and events are calling that method.  Based on the type of event, you'll know the arguments order (check Servoy documentation).  For example onAction passes in JSEvent as the first argument.  However onShow passes a boolean value of isFirstLoad as the first parameter, and the JSEvent as the second parameter.  

 

So, now we need to change our method based on the type of event.  Lets assume an onAction event.  Lets pretend this is the code of the method:

 

/**

 * @properties={typeid:24,uuid:"91FA7A4E-81E4-4484-9588-D5B87D7D77D9"}

 */

function test()

{

 

var myVar = arguments[0]

application.output(myVar)

}

 

 

Were going to change the method to look like this:


 

/**

 * My Test Method

 * 

 *  @param {JSEvent} event the event that triggered the action

 *  @param {var} myVar the input variable

 * 

 * @properties={typeid:24,uuid:"91FA7A4E-81E4-4484-9588-D5B87D7D77D9"}

 */

function test(event, myVar) //EWF

{

application.output(myVar)

}

 

The base changes are:

-Change the arguments to be passed in the function constructor, instead of through the arguments array

-Use JSDoc to document what the arguments are (name, type, order, and description)

-Remember to make the order correct depending on event type.  Since this was on onAction, I modified the function to make the event the first argument

-Notice the comment tag of "//EWF" on the function.  If you take a look at your "Tasks" panel on the bottom, you'll see that show up.  So now you have a quick reference to all of the code changes involved in changing code for the Event Warning issues

 

Finally, we need update all of the places that are calling our function (since we've changed the parameter order).  So, go to Search->Search again and search for the function by name.  The results show you all of the places calling that function. Go through and update all of them with the updated parameter list.  For example, a function like below:


forms.adm_frm_main.test("test")

 

 Will now look like this:

 

forms.adm_frm_main.test(null, "test") //EWF

 

Notice that I passed null for the event parameter since we don't have one here.  I also added the comment for EWF so I can keep track of my changes for this.  NOTE:  On your search, keep in mind you may have multiple methods with the same name, like "test", so make sure you only update the correct ones.

 

I hope that helps you in your Servoy conversion.  If you need any expert assistance in upgrading to Servoy 5, please contact us and we can assist you.  We have several packages prices specially for Servoy 5 conversion assistance.  Also, if your looking for an easier way to get a list of what type of events are calling your methods that need to be changed, check out our Servoy Upgrade Assistant (Beta)