Checking Plug-in Existence in Servoy

Servoy Plug-ins are used to extend Servoy’s capability to some extent. We can add Servoy Plug-ins to add more feature to our application which can not be doable with the default installation. Servoy default installation is also coming with number of Plug-ins. We can use them in our application or we can also use Free and Commercial third party Plug-ins.
Let’s think about a situation, where, you have used a Third Party Plug-in in your application. And, while installing the application, you forgot to install the Plug-in at your client’s end, or the Plug-in could not initialize at your Client’s end for some reason. Then, when your Client, tries to run the application, he/she will get the “method not found error”. This is due to the fact that, the Servoy Application Server can not able to find the Plug-in; and ends with throwing a method not found error.

The Below, TIP, explains about, How you can address the above situation by check whether the required Plug-in is properly installed or not.

Before using any Plug-in, it is recommended that you should check the Plug-in Existence. If the Plug-in is not found, you can show some informative messages to the user. So, the user will come to know that, Okay, THIS Plug-in is not found, so he/she tried to install the same or will contact the Administrator for the assistance.

Let’s take in to account our mfServerUtils Plug-in for Servoy. So, you are using the Plug-in in your code for alerting all remote clients connected with the Servoy Application Server.
//Check for access-code

var appServer = null;

var access = plugins.mfServerUtils.checkAccessCode(”);

if(access) {

//Get Application Server Instance

appServer = plugins.mfServerUtils.getApplicationServer();

}else {

application.output(‘Oops!! access-code does not match.’);

}

//Alert all clients connected to the Application Server

appServer.alertAllClients(‘Hey, this message is from the server.’);

The above code will send the alert message, to all the clients connected to the Server. If you run the code with out installing the mfServerUtils Plug-in, then you will get the error like below:

TypeError: Cannot call method "checkAccessCode" of undefined

We can add a small piece of code to check the Plug-in existence and show an informative message, if not found.

if(!plugins.mfServerUtils) {

plugins.dialogs.showErrorDialog(“Error!!”, “mfServerUtils Plug-in not found. \

Kindly, contact with the Administrator for assistance.”);

return;

}

//Check for access-code

var appServer = null;

var access = plugins.mfServerUtils.checkAccessCode(”);

if(access) {

//Get Application Server Instance

appServer = plugins.mfServerUtils.getApplicationServer();

}else {

application.output(‘Oops!! access-code does not match.’);

}

//Alert all clients connected to the Application Server

appServer.alertAllClients(‘Hey, this message is from the server.’);

In the above code, I have added an IF statement to check the Plug-in existence and showing an informative message, if the Plug-in is not found. The statement, plugins.mfServerUtils will return true if the mfServerUtils Plug-in installed successfully or false if not.
So, this way you can check the Plug-in existence before using any Plug-in in your code. This way you can make your application stronger.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!