Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

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
0
ninteen83
Asked:
ninteen83
  • 6
  • 3
  • 2
  • +1
1 Solution
 
HemanthaKumarCommented:
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
 
qwaleteeCommented:
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
 
ninteen83Author Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

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

0

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.

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