This topic is locked

Setting Defaults with sesssion vars

3/6/2009 4:39:58 PM
ASPRunnerPro General questions
S
sfkjeld author

What is the easiest way to value fields with default values (that are in session vars) when a record is added or edited? ie: I have the username in session("UserName"). Would like to store it in the [LastUpdatedBy] field.
I see events for adding additional records or records to another table, but I don't see an event to value fields not displayed in the Add/Edit forms, in the current record.
Thanks

E
ErinSigma 3/6/2009

There are a few ways to do this:

  1. Set it here. Visual Editor -> PROPERTIES (for the field) -> Default Value
  2. OR do so in the Before Record Displayed Event for the table.

S
sfkjeld author 3/6/2009

I set the Default value to session("Username") and I made it readonly. I see it the field in the Add form, but the record still does not save. Username is a unique tho. Does that matter?
I would rather not show the username field at all on the Form, but I don't see how to suppress it's display.
How do I value the record's field with a session var in the Event you mentioned?
Thanks

There are a few ways to do this:


  1. Set it here. Visual Editor -> PROPERTIES (for the field) -> Default Value
  2. OR do so in the Before Record Displayed Event for the table.

E
ErinSigma 3/6/2009

I think the actual question has changed, anyway to deal with this new information, try something like this:
To hide info use something like this:
xt.assign "FIELDNAME_fieldblock",Ucase(SESSION("UserID"))="BOB"
Replace Fieldnamewith your Column, session("UserID") is an example and "BOB" is the qualifier.
Do this in: Sub BeforeShowEdit(xt,templatefile)
As for the Session Variable being displayed, this should cover it and the Field/Column will receive the default value assigned as previously mentioned.
This is for HIDING, Disablingis another issue, this may help:
Insert and ASP code snippet at the end of the Appropriate page.
if Ucase(Session("UserID"))<>"BOB" then

Response.Write "<script>document.editform.value_FIELDNAME.disabled=true;</script>"

end if