How to get the the app's name in runtime?

How to get the the app's name in runtime?

  

Hi everyone,

In runtime, how can I know the name of the app (not module) that:

1) the running function/ action belongs to? E.g. how can I make a "GetAppName()" function that lives inside the app "ToDo_Core" that returns a string with the app name?

2) is the top-most app being executed? E.g. a user launching the "ToDo" app that internally calls a "ToDo_Core" app that has a "ToDo_Core/GetAppName()" function that should return the string "ToDo" (the name of the app that was originally run by the user). Something similar to "GetEntryEspaceName()".

Does GetEntryEspaceName() is not solving you purpose ?



Regards

-PJ-

Hi Pramod, the GetEntryEspaceName() gives me the module (eSpace) name. I want the name of the app that the module belongs to.

Here you go,

Try this it should give you the correct output.

SyntaxEditor Code Snippet

GetApplicationName(GetOwnerEspaceIdentifier())


Regards

-PJ-

GetApplicationName... I don't find that function. Is it a System function?

How can I know the application from the eSpaceId? Only by querying the meta model tables? Isn't there a more efficient way?

Hi Kelson,

Querying the meta model is indeed the only way to get the current Application name, afaik.

This you can find in Rich widget

GetApplicationName(GetOwnerEspaceIdentifier())

Regards

-PJ-

Hi,

Let's consider the following scenario:

  • the are 2 applications: AppA and AppB
  • AppA contains some "tools" module, which exposes an action, let's name it: GetCurrentApplicationName, that simply calls GetApplicatioName
  • AppB references this "tools" module and its GetCurrentApplicationName action
  • both apps contain screens with a button that calls GetCurrentApplicationName
  • in both cases we get the answer: "AppA"

This means that GetApplicationName returns rather static name, not a really runtime application name.

Is there a way to obtain from GetCurrentApplicationName, called from AppA and AppB, the answers: "AppA" and "AppB", accordingly?


Regards

Tomasz

Hi Tomasz. The code that you are describing is correct - when the GetOwnerEspaceIdentifier executes, it returns the "tools" module, no matter what app calls it. There's no way to retrieve the module that called the "tools" module.

You may try using GetApplicationName(GetEntryEspaceId()) instead and see if that works for you. The difference is that:

  • GetOwnerEspaceIdentifier() returns the module that defined the code that is running. In your case, because you're evaluating GetOwnerEspaceIdentifier() inside the "tools" module, it will always return its identifier, and you'll always obtain the same result.
  • GetEntryEspaceId() returns the identifier of the module that started execution. This is usually the name of the module that appears in the URL of your browser. If you evaluate this inside the "tools" module, it won't return the "tools" id, but instead the identifier of the entry module.

Nice info Leonardo.


I was exploring a little further based on that and realized that those functions only exist on the server side. 


On a mobile app you can't get that info only by calling client side actions.


So I did the following app:

The "Other Module" contains a server action that calls GetApplicationName(GetEntryEspaceId()).


So, I did a screen with three options:

  • Call to server side action from "OtherModule" using GetApplicationName(GetEntryEspaceId()) 
  • Call a plugin I recently did to get the app name and version from Cordova
  • Call client side GetEntryEspaceName()



The results are:

  • Server App Name - MobileSandbox
  • Cordova App Name - MobileSandbox
  • Client Side Entry Space Name - MobileSandboxApp


Cheers,

Renato


leonardo.fernandes wrote:

Hi Tomasz. The code that you are describing is correct - when the GetOwnerEspaceIdentifier executes, it returns the "tools" module, no matter what app calls it. There's no way to retrieve the module that called the "tools" module.

You may try using GetApplicationName(GetEntryEspaceId()) instead and see if that works for you. The difference is that:

  • GetOwnerEspaceIdentifier() returns the module that defined the code that is running. In your case, because you're evaluating GetOwnerEspaceIdentifier() inside the "tools" module, it will always return its identifier, and you'll always obtain the same result.
  • GetEntryEspaceId() returns the identifier of the module that started execution. This is usually the name of the module that appears in the URL of your browser. If you evaluate this inside the "tools" module, it won't return the "tools" id, but instead the identifier of the entry module.




Leonardo,

GetEntryEspaceId work as expected. It is not a solution for all cases (it fails when using a screen shared by several applications) but in many cases it is good enough.

Regards

Tomasz


What do you mean with "having a screen shared by several applications"? Screens can only be shared by redirecting to it. If you have been redirected to a screen that belongs to Application A, then you *are* in Application A, no matter where did you came from.

Yes, of course. Therefore, when I reach from AppA for a screen from AppB, I must manually supply ApplicationId. It's just a statement.

Regards

Tomasz