Global Token value retrieval

Hi

I am planning on using global tokens to initialize values for specific environments. For example a token name HOST_ENV with a return value of “development” to set some variables related to that environment. I created a script token with the return value, however I need help on, how can I retrieve the token value in something like:

var myEnv = “https://” + getViewParameterByName( "HOST_ENV" ) + “.myDomain.com/LogOn”

Thanks

Where would you need to store these global values / tokens?

I’m not sure that I understand what you need, but here’s how to store global variables.

You could use window if you are using it with a page.
window.host_env = "development;
and then retrieve it like any variable using window.host_env, or just with host_env as it available anywhere on the page.

If you need it to stay between pages, you can use the sessions variable.

sessionStorage.setItem("host_env","development");
and retreive it
var item= sessionStorage.getItem("development");

Hope this helps

Hi David

Thanks for replying. Those are valid elements, but I am talking about “Custom Token” . Setup->Tokens->Add Script Token

I created one that return the label ‘Development’. The question is, how do I retrieve the value on a script?

Thanks

Rey

Hi Reynaldo

I’ve never used that so I can’t help unfortunately.

I would start investigating by looking at https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/data/TokenService/cindex.html but I may be totally wrong.

Good luck

Hi Reynaldo,

Thank you for your inquiry. As per my understanding of your use case, you have created a script token named HOST_ENV and want to get the value of this token in some custom script. If this is your case, then you can make use of token service and get the value of your HOST_ENV token.

In this case, you will have to use the resolveToken method.

You can refer to the JavaScript API documentation for this function below:
https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/data/TokenService/Methods/resolveToken.html

Using this function, I have prepared a sample script that you can refer to for resolving tokens:


/resolve token/
var tokenService = this.getService(“TokenService”);// assuming you are using this code on the ready event of your dashboard
var resolvedTokenValue = tokenService . resolveToken ( “14115041-f333-4c22-b1e9-a0dec39e1a1d” ); //id of your HOST_ENV token

resolvedTokenValue . done ( function ( resultString ) {

console . log ( resultString ); //resultString contains the value of your token

});


You can get the id of your script token from the admin panel (Admin>>System>>Tokens>>Edit the HOST_ENV token).

This will return the value defined for the token:

I hope this answers your question.

1 Like

Thanks Pankaj that works perfectly!