Today's question after RTFM. I hope it's not too dumb. Is it possible to call Session.SetSessionVar (or other framework functions) from within a javascript script tag? According to the internet I should be using local or session storage in the browser but I'd prefer to use the app session vars.
TIA
Not directly. But you could make an HTTP call using JavaScript (a REST client call) to your service or any endpoint and set them that way.
You'll want to be very careful with that though because client code can be spoofed since it's out in the open and can be modified.
+++ Rick ---
Thanks. I appreciate the feedback. That's more complicated than I need to get for this. I'll go the cookie route instead.
What's complicated about making a JavaScript call ot the server? It's a few lines of code - single if it's a real simple.
Be careful using cookies or trying to manipulate them from the client. Lots of restrictions and ad blockers prevent this if that's what you're thinking. If you need to set state on the client I suggest set it into page hidden form variables and post it back when you submit the page, or as previously suggested make a JavaScript HTTP call to the server and post it out of band if you can't wait for a proper page Postback.
+++ Rick ---
I suppose nothing is complicated once one has a reasonable amount of experience with the process in question. But I'm not there yet with this. 😃 I'll get a bit more specific about what I want to accomplish.
In OnProcessInit
I am running a little method that checks a queue table which is updated asynchronously by an external partner. If it finds data to review my original plan was to set a WWC session var for that user - m.Session.setSessionVar([batchcomplete],[yes])
. I've added a js alert-style modal in the page footer which will check that value and if it's "yes", pop up the modal and allow the user to select from a couple of processing actions or to ignore the pending review for the duration of the session. I'd like to write back to that session var from the javascript if the user selects the option to ignore - m.Session.setSessionVar([batchcomplete],[ignoreme])
Ultimately the goal is to show or suppress this modal for the lifetime of the user session. Per your original answer I can't just call the setSessionVar
function directly from js. Going the cookie route it's very simple (for me) to handle the responses from that dialog as well as clear on logout. If I use the ajaxJson function I will have to write a service to handle that call, correct?
You've also indicated that regardless of using a cookie or a service call, I have to be careful about how those things could potentially be manipulated by a malicious actor. Which one would you say is more concerning: the endpoint which would be protected by usersecurity, or the application session cookie which only cares about 2 values (yes or ignoreme) and will not persist? Or now that I've shared more specific details on what I want to accomplish you have some other advice?
If I use the ajaxJson function I will have to write a service to handle that call, correct?
No you don't need a separate service - you just need a separate Process method in your existing Process class.
You can just have a method in your existing Process class and handle the incoming JSON (or whatever data you're sending manually - or use wwJsonService explicitly to handle the entire process).
Which one would you say is more concerning: the endpoint which would be protected by usersecurity, or the application session cookie which only cares about 2 values
Cookies should never be used for client side anything. Too much potential for something going wrong where you can't judge the consequences plus there's a good chance the browser will block it.
I would either make a service call or if you can wait until the request is posted use hidden form vars to send the results back to the server. The latter is probably the most appropriate, but it can also be tampered with potentially just like the other two.
+++ Rick ---
Thanks. I will take a closer look at adding a simple process method to do what I want. Much appreciated, as always.
And that couldn't have been much simpler. Goodbye, evil cookies. Hello, session. 😃
Thanks again, Rick.
Next general n00b question. I appear to be running into some jquery conflicts. We are using jquery-3.3.1 from a CDN. I am loading ww.jquery.ws after that. Tips or tricks (or help content) you can point me to that will help identify the conflict, and best practices to address this sort of thing.
TIA
(export more proofreading emails as I pore over your help content in my never-ending search for clues...)
What is the conflict? I can't recall what version is shipped with WWWC but it's reasonably recent and there's should be very little churn in jquery releases at this point.
Web Connection explicitly adds the jquery reference to the layout page and you can just replace that with the version you need. Pretty sure WWWC will work with the lower version (WWWC uses 3.4.1)
+++ Rick ---
I was mistaken because I misinterpreted what Rod told me. There was no conflict causing an error but a js function we use for tooltips wasn't being loaded. We changed the order that the jquery libraries get loaded and that seems to have corrected our issue.
Thanks again.