• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

cookies

I have a multi value dialog list called 'Roles' this does a look up of all the user roles available in the ACL.  A user will then select which roles they want to and submit the form.  On submission this should call the javascript to set the cookie value.

The cookie value will need to store the roles the user has selected in 'Roles' field.  There will then be a field called 'EffectiveRoles' stored on all the forms in the database which will need to get the values of the 'Roles' field stored in the cookie.  If the cookies is empty ie the user has not submitted the form then the field will be set to @UserRoles.

I need to know how to set the multi values of the 'Roles' field in the cookie and then retrieve them in the 'EffectiveRoles' field.
0
fayeb
Asked:
fayeb
1 Solution
 
AndrewJayPollackCommented:
why do that at all?  Why not just use @UserRoles on all the forms?  Storing them locally allows them to be hacked by a smart user.
0
 
fayebAuthor Commented:
The customer wants the user to be able to select what roles they would like to use.  It's whats been asked for!
0
 
fayebAuthor Commented:
All I need to know is how do i read the values from a multivalue field and set them in the cookie e.g. Roles=[role1],[role2];
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
HemanthaKumarCommented:
In cookie, seperate roles by comma

~Hemanth
0
 
fayebAuthor Commented:
Whats the javascript that does this?
0
 
ZvonkoSystems architectCommented:
Ok, here are the formulas.

On the form where your DialogList named Roles is put this into your DialogList options formula:
@Trim(@Replace(@UserRoles;"$$WebClient";""))

The checkbox for AlowMultipleValues is checked.

On this form where the DialogList "Roles" is placed you need two things:
1.) This scropt in JSHeader section of the Form:
function setRoles(){
  theRoles=document.forms[0].Roles;
  selRoles=""
  for(i=0;i<theRoles.options.length;i++)
    if(theRoles.options[i].selected)
      selRoles+=','+theRoles.options[i].text;
  if(selRoles>'')
    document.cookie="Roles="+escape(selRoles.substr(1))+";path=/;"
}

2.) This script invocation in Form's onSubmit event:
setRoles()

So, now on the same Form or another Form where your MultiValue Field named "EffectiveRoles" is you need two Fields:
1.) Field named "HTTP_Cookie" best as ComputedForDisplay with this @Formula:
HTTP_Cookie

2.) Field named "EffectiveRoles" with this @formula:
FIELD HTTP_Cookie:=HTTP_Cookie;
selRoles:=@Left(@Right(HTTP_Cookie;"Roles=")+";";";");
@If(selRoles="";@Return(@Text(@Trim(@Replace(@UserRoles;"$$WebClient";""))));"");
@Explode(@ReplaceSubstring(selRoles;"%2C":"%5B":"%5D";",":"[":"]");",")

I think, best choice for Field "EffectiveRoles" is to be Computed with the upper value formula.

Give it now a try.

So long,
Zvonko

0
 
fayebAuthor Commented:
Thanks this is exactly what I needed.
0
 
ZvonkoSystems architectCommented:
You are welcome :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now