Changing one document effects another documents ..

Posted on 2004-04-20
Last Modified: 2013-12-18
I have a form with 5 fields

EmpNo, Ename, Module, StartDate, EndDate

I've created 3 documents and a the View is shown below:

Empno    Ename          Module    StartDate    EndDate
             Ninteen83      ABC         01/01/04    01/31/04
             Ninteen83      BBC         02/01/04    02/29/04
             Ninteen83      CBC         03/01/04    03/31/04

if we extend the Module 'ABC' and change the EndDate (from 01/31/04) to 02/15/04 .. Can these 15 days be added to the other modules ??

I mean to ask that if we change the EndDate of one document .. the StartDate and EndDate of the following documents can be changed ??

Empno    Ename          Module    StartDate    EndDate
             Ninteen83      ABC         01/01/04    02/15/04
             Ninteen83      BBC         02/16/04    03/15/04
             Ninteen83      CBC         03/16/04    04/14/04

I tried my best to find out a solution but couldn't get .. and I'm very poor in LotusScript :(

Any help
Question by:ninteen83
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
LVL 24

Accepted Solution

HemanthaKumar earned 400 total points
ID: 10868756
Try this

Dim s as New NotesSession
Dim db as NotesDatabase
dim view as NotesView
Dim col as NotesDocumentCollection
Dim doc as NotesDocument
Dim ws as New NotesUIWorkspace
Dim note as NotesDocument
Dim dt as NotesDateTime

set db = s.CurrentDatabase
set view = db.GetView( "EMPNOView" )
set note = ws.CurrentDocument.Document
set col = view.GetAllDocumentsByKey( note.EmpNo(0) )        ' THis is EMp NO
set doc = col.GetFirstDocument
diff = note.Diff            ' Maintain a simple computedfordisplay field which will calculate diff in end date and previous end date.. Say 15 in your above example
while not doc is nothing
if doc.UniversalID <> note.UniversalID  then
set dt = New NotesDateTime( doc.StartDate(0) )
call dt.AdjustDay(diff)
doc.StartDate = dt.DateOnly
set dt = New NotesDateTime( doc.EndDate(0) )
call dt.AdjustDay(diff)
doc.EndDate = dt.DateOnly
doc.Save true, false
end if
set doc = col.GetNextDocument(doc)


LVL 31

Expert Comment

ID: 10869821
Hemantha, your code will change modules that finish earlier, too!

E.g., change BBC from 2/29 to 3/1.  That should only affect CBC, but your code will change ABC as well!

A simple change would be, instead of:
    if doc.UniversalID <> note.UniversalID  then


    if doc.UniversalID <> note.UniversalID AND doc.startDate(0) >= note.endDate(0) then

Author Comment

ID: 10875296
Thanks Hemantha for the script .. but the agent is not running.
There are some other fields in the form.

DocStatus ---------- Number, Editable, 0 (default value)
XDays ---------- Number, Editable, 0
ExDate ---------- Date\Time, Computed, @If(@IsNewDoc;""; @If(XDays="";""; @Adjust(EndDate;0;0;XDays;0;0;0) ) )

Extend Module - (Hotspot Button) ---------------

FIELD XDays:=@Prompt([OkCancelEdit]; "Extend Training Period"; "How many days do you like to extend the module?"; "");
FIELD ExDate := @Adjust(EndDate;0;0;XDays;0;0;0);
FIELD EndDate := ExDate;
FIELD DocStatus:=4;

Save & Close - (Hotspot Button) ---------------

   @If(ExDate!="";FIELD EndDate := ExDate;@Success) );
@Command([ToolsRunMacro]; "DocExtend");
FIELD XDays:=0;

By Employee | BEMPV - (View) -------------

Empno    Ename       DocNo  Module     StartDate   EndDate
             Ninteen83      1       ABC         01/01/04    01/31/04
             Ninteen83      2       BBC         02/01/04    02/29/04
             Ninteen83      3       CBC         03/01/04    03/31/04
             NShah           1       NAB         01/15/04    02/14/04
             NShah           2       NBB         02/15/04    03/14/04

DocExtend - (Agent) ------------
Trigger : On Event
Runtime : Action menu selection
Target : All new & modified docs

      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim col As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim ws As New NotesUIWorkspace
      Dim note As NotesDocument
      Dim dt As NotesDateTime
      Set db = s.CurrentDatabase
      Set view = db.GetView( "BEMPV" )
      Set note = ws.CurrentDocument.Document
      Set col = view.GetAllDocumentsByKey( note.Empno(0) )        
      Set doc = col.GetFirstDocument
      diff = note.Diff            
      While Not doc Is Nothing
            If doc.UniversalID <> note.UniversalID And doc.StartDate(0) >= note.EndDate(0) Then
                  Set dt = New NotesDateTime( doc.StartDate(0) )
                  Call dt.AdjustDay(diff)
                  doc.StartDate = dt.DateOnly
                  Set dt = New NotesDateTime( doc.EndDate(0) )
                  Call dt.AdjustDay(diff)
                  doc.EndDate = dt.DateOnly
                  doc.Save True, False
            End If
            Set doc = col.GetNextDocument(doc)


When I click on 'Extend Module' button it asks for the days .. I enter 5
then I click on 'Save & Close' it extends the EndDate to 5 days but doesn't change the following documents.
Independent Software Vendors: 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!


Author Comment

ID: 10877066
any help ..
LVL 13

Expert Comment

ID: 10877919
ninteen83 has contacted me for help as this issue is getting real urgent.
Hemanth / qwaletee, can you please review this and/or make corrections to following suggestion?

Hemanth left you following note in his code:

diff = note.Diff            ' Maintain a simple computedfordisplay field which will calculate diff in end date and previous end date.. Say 15 in your above example

"note" Is the back-end document of the one you are extending on the front end. "Diff" Is the field on it that is used to store the difference between the old and the new end date.... your "XDays" field.

Since the agent can't find anything called "Diff", nothing really gets adjusted. You may notice the last modified date/time change though.

If you modify that line to:

diff = note.XDays

then you may be well on your way!
I can't run the full code to perform a full test. The prompt returns a string value to the field, while a AdjustDay requires an integer. "diff" Is not declared (i.e. variant). Perhaps it covers the possible error, but if you get a "type mismatch", you may need to force "diff" to an integer (CInt()).
In addition: diff is reading a field, so i'll get an array assigned! diff = note.XDays(0) may also be part of a solution.

Use the debugger, so you can check on the assigned values and any error line.

Good luck tomorrow!
LVL 24

Expert Comment

ID: 10878396

Read the code step by step and first make sure that you understand the idea.. so it becomes simpler for you to add your modifications as my code will never be a copy paste soln.. it will be a guidance. As pointed out by CRAK.. you have to make some substitutions and I have to an extent commented on those in the script. The script essentially rely on diff in days which has to be altered ..

A small correction .. it should be

diff = note.XDays(0)


Author Comment

ID: 10878666
Thank you CRAK .. for the great help. :)

Once I was getting  "Type Mismatch" error .. but now the error doesn't appear.

Hemantha !! I went through your code and read it step by step .. I'm sure that now I understand the script :)

diff = note.Diff       has been replaced by      diff = note.XDays(0)

but still when I extend a module it only changes the EndDate of the current doc .. It doesn't effect on the following docs ... if 2 docs are following the current doc, it shows the message "Documents changed" twice .. but doesn't change any of the docs' startDate n enddate :(
LVL 24

Expert Comment

ID: 10878752
Can you debug and see if the EndDate and StartDate are getting the values after the adjustday function ??

Author Comment

ID: 10879223
I'm poor in debugging the script .. let me check if I can find any bug

Author Comment

ID: 10896932
The agent works fine now. Thanks Hemantha, qwalette and CRAK ..
LVL 13

Expert Comment

ID: 10897056
You're welcome.

Was this fast enough? Did you manage to "keep the big guy happy"?

Author Comment

ID: 10898021
Hi CRAK .. yes he became happy .. and thats all bcoz of you :)


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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