How to make sure a user cannot EDIT a date field once it's created


I have a date field, I want a user to be able to create a date, but not have this user able to edit the data after that. I want to use MGR role to allow MGR to edit this date.

I am able to do this for the WHOLE form, however I am NOT able to do this JUST for ONE field / date field...

Here's my code I use on Querymodechange

Sub Querymodechange(Source As Notesuidocument, Continue As Variant)
      Dim curdoc As notesdocument
      Set curdoc=Source.document
      If Not ( source.EditMode ) Then
  'user_roles = Evaluate( "@UserRoles" )
            user_roles =Evaluate("@UserNamesList")
            Forall role In user_roles
                  If ( role = "[MGR]")   Then
                        Exit Sub
                  End If
            End Forall
      End If
      If curdoc.STATUS(0)="Open" Or curdoc.STATUS(0)="On Hold" Then
       'Exit Sub
      End If
End Sub

and under Postmodechange

Sub Postmodechange(Source As Notesuidocument)
      Dim status As String
      status = Source.FieldGetText("Status")
      Call Source.FieldSetText("StatCheck" , Status)
End Sub
Who is Participating?
mbonaciConnect With a Mentor Commented:
Two things, first you don't need "=0" in:
@IsMember("[MGR]";@UserRoles) = 0


Second, you can use @IsDocBeingEdited inside hide-when formula, instead of "You must be in Edit Mode to Change the value of a field".
Create Computed text bellow field and then use hide-when formulas to control to whom you'll show each of them.
One suggestion, looking at your PostModeChange event code, you should use

    if source.EditMode Then

to check whether user changed doc to edit mode or read mode (click on <ctrl + e> while in edit mode will cause error in your current code).

One more thing, computed text should have this as its formula:

    @Text( name_of_your_field_without_quotes; "D0" )

if you want to show only date component of date/time field.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

car701015Author Commented:
Thanks mbonaci, one problem though, if I make a computed field, the original field has an advance date, meaning that it will permanently hide, when a user creates a new record, I want them to decide to either use existing advanced date or they set a new date.

tks for the other mention...
Not computed field, Computed text.
You don't change anything on your existing date field (except hide formula), simply position the cursor right of it and click enter.

Then choose

    Create > Computed text

and write the formula I mentioned in the lower right frame.
Just a simple demonstration:

In your current date field's hide-when properties enter this formula:


and in <Computed text> properties this one:


This way the two paragraphs are mutually exclusive, the date field will show before, and the <computed text> after the doc is saved.
You can base the hide-when formulas on a "flag field" (non-existent on the form, written in run-time only to a document).
That way you can manipulate hide-when formulas so you can customize the form behavior as it suits you best.
car701015Author Commented:
Ah, ok, I got this

field hide formula...

@IsMember("[MGR]";@UserRoles) = 0 | !@IsNewDoc

computed text

@Text(@Date(date_target); "D0" )

hide formula

but I am the MGR, if I want to change the date, it doesnt allow me to...
car701015Author Commented:
oh... and since the computed text... I am now getting

"You must be in Edit Mode to Change the value of a field"
car701015Author Commented:
!@IsDocBeingEdited | @IsNotMember("[MGR]";@UserRoles) was used - Thank you very much!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.