Get solution type at runtime

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Get solution type at runtime

Postby steve1376656734 » Sun Mar 17, 2024 11:37 am

Hi all,

Does anyone know if there is a way to determine at runtime if the solution being run is a post-import module? I have scoured the docs but cannot seem to find any way of getting this information.

Use case:
I have a core module for my solution that is referenced in the both the main solution and the post-import solution. I want to be able to change the behaviour within one of the core module methods depending on the solution type it is called from, similar to how we do it if we are running in developer by utilising application.isInDeveloper().

TIA
Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: Get solution type at runtime

Postby mboegem » Sun Mar 17, 2024 3:36 pm

Hi Steve,

I don't think there is a function for this and although I haven't tried the outcome, here are some ideas that might help you out.

1) application.getApplicationType() > this should most likely return APPLICATION_TYPES.HEADLESS_CLIENT for the post-import module, but APPLICATION_TYPES.NG_CLIENT for the main solution.
2) application.getSolutionName() > I would expect this to return the name of your post-import solution when the code is running as part of this.
3) set a scope variable on the solutionOpen method from the post import module.

3rd one will definitely work.

I haven't checked 1 and 2, but I would be surprised of the outcome is different.
Option 1 might not be sufficient if part of the core module is also used in a batch processor as that will definitely return APPLICATION_TYPES.HEADLESS_CLIENT
Of course everything depends on the kind of behaviour you are trying to resolve, if this is a thing you want to avoid running HC in general (like not showing dialogs) then it might be enough.

I am definitely interested in the outcome in case you are going to test 1 and 2 :-)
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1752
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Get solution type at runtime

Postby steve1376656734 » Sun Mar 17, 2024 3:51 pm

Hi Mark,

Thanks for the suggestions.

I had already rejected 1 for the exact reason you suggested regarding batch processing (we have both batch processors and ad-hoc background jobs).

I have tried number 2 and it does give the desired result so I am going to use that as a temporary solution. I hate the idea of relying on a fixed solution name (even using application.getSolutionName().indexOf('PostImport') != -1 to make it slightly more flexible is not ideal) as we have an internal framework that we developed that is used in multiple solutions . At least the indexOf will allow us to have different module names in different solutions.

I would much prefer something like application.getSolutionType() that returns a definite constant and then the solution name becomes irrelevant and avoids potential coding issues caused by a name change. I will file this as a feature request and see if it gets any traction.

Thanks
Steve
Steve
SAN Developer
There are 10 types of people in the world - those that understand binary and those that don't
steve1376656734
 
Posts: 330
Joined: Fri Aug 16, 2013 2:38 pm
Location: Ashford, UK

Re: Get solution type at runtime

Postby mboegem » Sun Mar 17, 2024 4:15 pm

Hi Steve,

why don't you use the 3rd option if you don't want to rely on a name?

Add the variable to a scope in your core module.
Create a function that will return the value of the variable.
And for each postImport module you are using, simply set the variable in the onSolutionOpen function to true.
This way you keep it nice and clean as by default the isPostImport function will return false.

Code: Select all
/**
* @type {Boolean}
* @private
*/
var $bPostImport = false;

function isPostImport() {
   return $bPostImport;
}
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1752
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 20 guests

cron