Hello,
I would like to know if there is a way to use a local or an instance variable in my WebApp. I want some variables to communicate between different activities in my webApp with no access or read only access from the client side. I'm already using the context variables (ctx.vars) but those are Global and are exposed to the public and can be easily changed from the browser (These variables are used server side only and there is no need for them to be displayed elsewhere) .
Thank you.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hello @dhfw ,
I have one little (hack) trick to achieve what you want, it is not official and could stop working anytime (works for years). Also works (for years) in workflows. This way I do not have to stringify objects but move then between activities and access them as objects everywhere else:
How to?
var DL:{}
Also it works in page activity and in every other activity that uses JSSP inside web app
<%=DL.variable%>
Marcel Szimonisz
MarTech Consultant
for more tips visit my blog
https://www.martechnotes.com/
Hi @dhfw
To avoid SQL injections, use bound parameters with $().
Eg.
sqlGetInt( "select iRecipientId from NmsRecipient where sEmail = $(sz) limit 1", request.getParameter('email'));
sqlExec("UPDATE "+vars.tableName+" SET sEmail=$(sz) WHERE iId=$(l)", cleanedEmail, record.$id);
For more information click.
Also there's a Blog which you can go through.
Documentation of binding the parameter.
Also the variables that is defined in the variables tab under properties of WebApps, flows throughout the WebApp and can be used anytime in any of the activity.
Regards
Views
Replies
Total Likes
Hi @AkshayAnand
Thank you for your response but this is not really what I need. What I need is an instance variables similar to the variables used in workflows like described Here to send data between different activities like a JS activity and a Test activity.
instance.vars.foo = "bar1"
vars.foo = "bar2"
task.vars.foo = "bar3"
I am aware of there variables tab under properties of WebApps but those variables are in the Global context. As I mentioned above, i'm already using the global ctx.vars to communicate between the client side and the server side of the WebApp. What I need is a secure way to communicate between different activities server side exclusively.
I hope my description was clearer this time.
Thank you.
Regards.
Views
Replies
Total Likes
Hi @dhfw
Thank you for your explanation. As mentioned in my previous comment, you can use bound parameters with $() for secure transfer as instance variables can't be used. (instance.vars.x or vars.x will throw undefined error).
Repasting the links :-
Documentation of binding the parameter.
For more information click.
Also there's a Blog which you can go through.
Regards
Views
Replies
Total Likes
Hi @AkshayAnand
Thank again for your response but I still fail to see how I can use bound parameters to communicate variables between two activities. These variables are server side only and are in no way parameters sent from the client side. They are not even inserted into the database, there is no SQL (update, select, insert) involved in my use case.
I'm aware that instance variables can't be used, that's why I was asking for something similar or a turnaround.
Thank you once again.
Regards.
Views
Replies
Total Likes
Hello @dhfw ,
I have one little (hack) trick to achieve what you want, it is not official and could stop working anytime (works for years). Also works (for years) in workflows. This way I do not have to stringify objects but move then between activities and access them as objects everywhere else:
How to?
var DL:{}
Also it works in page activity and in every other activity that uses JSSP inside web app
<%=DL.variable%>
Marcel Szimonisz
MarTech Consultant
for more tips visit my blog
https://www.martechnotes.com/
Thank you @Marcel_Szimonisz, this seems like the closest solution to what I need.
Do you I think I can create multiple objects with a randomly generated name for each user instance to avoid conflicts and destroy these objects at the end of my webApp workflow as to not overload the server with useless variables ?
Views
Replies
Total Likes
Hello @dhfw.
sure you can create as many variables, and objects (arrays what not) this way. Give it a try and let me know how it went
Marcel
Views
Replies
Total Likes
Will do @Marcel_Szimonisz. Thank you so much.
Views
Replies
Total Likes
Hello @Marcel_Szimonisz .
The solution sadly didn't work for my use case
Passing variables between two activities works perfectly except for when there is an HTML page between them. The application probably re-execute the script when a client side request is made which resets the stored variables.
Result :
Result :
EDIT : I can actually make it work by rearranging some activities and declarations, so thank you so much for the help.
EDIT 2 : The test activity of the webApp only recognizes the formContext which is basically "ctx" and I sadly can not find way to use the variables declared in the JS script library in the test activity.
generated code :
Views
Replies
Total Likes
Hello @dhfw
Page will "reset" that special variable.. so you need to store to ctx.vars as string and then restore
Marcel
Views
Replies
Total Likes
Hello @dhfw,
Also are you sure you can change the ctx variables from client side?
Marcel
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies