Link to home
Start Free TrialLog in
Avatar of ninteen83
ninteen83Flag for Qatar

asked on

Changing one document effects another documents ..

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
ASKER CERTIFIED SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qwaletee
qwaletee

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
Avatar of ninteen83

ASKER

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.
any help ..
Avatar of CRAK
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!
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)

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 :(
Can you debug and see if the EndDate and StartDate are getting the values after the adjustday function ??
I'm poor in debugging the script .. let me check if I can find any bug
The agent works fine now. Thanks Hemantha, qwalette and CRAK ..
;-)
You're welcome.

Was this fast enough? Did you manage to "keep the big guy happy"?
Hi CRAK .. yes he became happy .. and thats all bcoz of you :)