Hello all,
I am making a fundraising page, and I'm a little confused on how to create a "variable" that exists in the page but keeps its value once the user changes it, leaves the page and another user comes in to see the changed value.
I am unsure if I use a static entity? Session variable?
Example:
I want these two to change once I make the change, but stay changed.
Thank you!
Hi Vinicius,
If you have an Entity that needs only a single record (as is the case with these kind of Entities that hold configuration data), this is the usual way to go:
Now with regard to your errors:
A Static Entity is, like the name says, static. You cannot change it. A Session Variable is, like the name implies, bound to the session and therefore user specific. I'm not really sure why you are thinking of Static Entities or Session Variables, why not just a plain ol' database Entity?
Hey,
You wouldn't use a static entity as these are for unchanging values. You could use a session variable, but it depends on how exactly you end up manipulating those values. Do they change very often? Are they specific to a user?
If one user changes the values for everyone, it makes it harder to propagate into a session variable: they're typically used to store user preferences, or user specific information. If its common data, you should store in the database inside an Entity.
If those values are specific to a User, I'd store them in a session variable.
The most straightforward solution is to create an entity to hold the value. If that's not preferable, you can also create a site property and then programatically set the site property value. The downside is that anyone who has access to the site properties in ServiceCenter can log in and change it.
I'll use an entity then. Thank you all!
@Kevin: using site properties for changing data is discouraged and bad practice! It has associated performance issues since it causes a cache flush etc.
Kilian Hekhuis wrote:
Agreed that it's not ideal, but if you start with the assumption that there is some reason an entity can't be used (maybe they're out of AOs??) it would be a viable alternative.
Ok I am using an entity, I want it to only have 1 entry that I can modify throughout the pages, screens etc. When I create the entity, it is originally empty, so I have to add an entry. To do that, I tried using the Create function from the entity function list, but it asks for a Source. What do I put for Source? When I used a variable, it asked for an ID which I don't have since its empty...
I'm a little confused.
Hello Killian! Thank you for pointing out the source +, it got rid of several of my variables ;).
I did everything you told me, and it worked like a charm! Thank you for being so precise, considerate and detailed in your explanation, I was able to update the values and they stayed there.
Glad I could be of help. Happy coding!