Script Change for Amateur

Posted on 2005-05-10
Last Modified: 2013-12-18
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

Question by:schmad01
    LVL 46

    Expert Comment

    by:Sjef Bosman
    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?

    Author Comment

    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?
    LVL 46

    Accepted Solution

    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.
    LVL 31

    Expert Comment

    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.

    Author Comment


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
    Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now