[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

Script Change for Amateur

Hello everyone,
Hope you are having a good day.

I have these scripts I use to check field changes.  One is for PostOpen and the Other is for QuerySave.  The fields that these refer to are text.  I want to change some fields on the form to date format.  What changes in the script have to be changed to accomodate the form change.  The fields that I am referring to are:


Here is the PostOpen script:
Sub Postopen(Source As Notesuidocument)
      Dim s As New notessession
      If Not Source.IsNewDoc Then
            Call s.SetEnvironmentVar("KeyFieldqcspecs" , Source.FieldGetText("qcspecs"))
            Call s.SetEnvironmentVar("KeyFieldkoshstat" , Source.FieldGetText("koshstat"))
            Call s.SetEnvironmentVar("KeyFieldmicrospecs" , Source.FieldGetText("microspecs"))
            Call s.SetEnvironmentVar("KeyFieldtoffhold" , Source.FieldGetText("toffhold"))
      End If
End Sub

Here is the QuerySave script:
Sub Querysave(Source As Notesuidocument, Continue As Variant)
      Dim ss As New notessession
      un = ss.CommonUserName
      dat = Cstr(Now)
      If Source.IsNewDoc Then
            Call Source.FieldSetText("Field2" , "" )
            Call Source.FieldSetText("Field3" , "" )
      Elseif Source.FieldGetText("qcspecs") <> ss.GetEnvironmentString("KeyFieldqcspecs") Then
            Call Source.FieldSetText("Field2" , un )
            Call Source.FieldSetText("Field3" , dat )
      End If
      Call ss.SetEnvironmentVar("FieldNameVariable" , "" )
      Dim dd As New notessession
      un = dd.CommonUserName
      dat = Cstr(Now)
      If Source.IsNewDoc Then
            Call Source.FieldSetText("kosh_name" , "" )
            Call Source.FieldSetText("kosh_date" , "" )
      Elseif Source.FieldGetText("koshstat") <> ss.GetEnvironmentString("KeyFieldkoshstat") Then
            Call Source.FieldSetText("kosh_name" , un )
            Call Source.FieldSetText("kosh_date" , dat )
      End If
      Call dd.SetEnvironmentVar("FieldNameVariable" , "" )
      Dim ee As New notessession
      un = ee.CommonUserName
      dat = Cstr(Now)
      If Source.IsNewDoc Then
            Call Source.FieldSetText("micro_name" , "" )
            Call Source.FieldSetText("micro_date" , "" )
      Elseif Source.FieldGetText("microspecs") <> ss.GetEnvironmentString("KeyFieldmicrospecs") Then
            Call Source.FieldSetText("micro_name" , un )
            Call Source.FieldSetText("micro_date" , dat )
      End If
      Call ee.SetEnvironmentVar("FieldNameVariable" , "" )
      Dim ff As New notessession
      un = ff.CommonUserName
      dat = Cstr(Now)
      If Source.IsNewDoc Then
            Call Source.FieldSetText("hold_name" , "" )
            Call Source.FieldSetText("hold_date" , "" )
      Elseif Source.FieldGetText("toffhold") <> ss.GetEnvironmentString("KeyFieldtoffhold") Then
            Call Source.FieldSetText("hold_name" , un )
            Call Source.FieldSetText("hold_date" , dat )
      End If
      Call ff.SetEnvironmentVar("FieldNameVariable" , "" )
End Sub

  • 2
  • 2
1 Solution
Sjef BosmanGroupware ConsultantCommented:
Is it an existing application? Then bear in mind that the fields in the existing documents will still have the old text values...

Both routines seem okay to me, since you use only text there. Did you try already what happens? In a test database of course?
schmad01Author Commented:
No I haven't tried changing the form fields and then seeing if the script still works(That is what you meant right?).  If it does work, the date field data will remain as a date format, right?

And yes, it is an existing application.  I was thinking that if this works, I would temporarily put Input translation as for example @Date(micro_date), then Refresh all docs.  Would that work?
Sjef BosmanGroupware ConsultantCommented:
That's what I meant indeed. If the fields contain coorectly formed dates, nothing will change.

The agent would work indeed, but if it's a very large app or you use unread marks, your users might not like you... It might be better to build in some simple checks, like
    @If (@IsTime(x); x; @Date(x))
or, in LS
    If TypeName(x)="DATE" Then
which is equivalent to
    If DataType(x)=7 Then ' or use V_DATE from lsconst.lss
Also, you'd have to change some views where the date is used, although views are usually very forgiving. You might have to se the date/time format in the column.
You don't need t do anything.  FieldGetText and FieldSetText treat all fields as if they are text, even if they are date or number fields.  Frther, the NOtes Editor treats all fields as text fields, but converts them to whatever format is appropriate when saving or evaluating.  That's why you can actually put garbage characters in a date or numbr field, and it won't balk until you save.

However, I would not have written the code this way for several reaons:
1) No error checking or validation
2) INstead if foreground operations (Field*etText), I woudl use the more efficient back end classes, though  that does mean paying more attaention to value types and validaion yourself.
3) No need to use environment variables.  Instead, create LotusScript variables in teh GLOCALS section of the form code, so that the values work across functions or across multiple calls to the same function.  Then, get/set the variables instead of the old environment variables.
schmad01Author Commented:

Featured Post

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.

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