Solved

Changing one document effects another documents ..

Posted on 2004-04-20
12
182 Views
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
112
             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
112
             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
0
Comment
Question by:ninteen83
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 24

Accepted Solution

by:
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)

Wend

~Hemanth
0
 
LVL 31

Expert Comment

by:qwaletee
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

...use...

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

Author Comment

by:ninteen83
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) ---------------

@If(!@IsDocBeingEdited;@Command([EditDocument]);@True);
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;
@PostedCommand([FileSave]);
FIELD DocStatus:=4;


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

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


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

Empno    Ename       DocNo  Module     StartDate   EndDate
112
             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
115
             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)
            
      Wend


---------------

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.
0
 

Author Comment

by:ninteen83
ID: 10877066
any help ..
0
 
LVL 13

Expert Comment

by:CRAK
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?


nineteen83,
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!
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10878396
1983,

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)

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:ninteen83
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 :(
0
 
LVL 24

Expert Comment

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

Author Comment

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

Author Comment

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

Expert Comment

by:CRAK
ID: 10897056
;-)
You're welcome.

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

Author Comment

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

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

  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…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

14 Experts available now in Live!

Get 1:1 Help Now