Link to home
Start Free TrialLog in
Avatar of kali958
kali958Flag for United States of America

asked on

Save current document and open a new document

I have a form for procedures, and there is a button that says Update Procedure, what I would like it to do is put the status of Archive on the current Procedure and then open up another form that inherits the data and let the user edit that document. (we have to archive the current procedure without changes due to the workflow and if we are audited on our procedures.)  I can get it to archive the current form and open a new form with the data, but I would really like it to close the first form.  Everytime that I put in @Command([FileCloseWindow]) on the button, it fails. Is there something I am missing, this is my current code I am using on the Action


@If(!@Command([ViewRefreshFields]);@Return("");"");
FIELD AllowClose := "1";
FIELD SaveOptions:="1";
FIELD End_Date:=@Now;
FIELD Status :="Archived";
FIELD Person := @If(Person="";@Name([CN];@UserName);@Name([CN];@UserName):Person);
FIELD Action := @If(Action="";"Archived";"Archived":Action);
FIELD ActionDate := @If(ActionDate="";@Now;@Now:ActionDate);

@PostedCommand([FileSave]);
@PostedCommand([Compose];"P_2");

@Command([ViewRefreshFields])

I have tried putting the @Command([FileCloseWindow]) before and after the Compose and I have also tried it as a @PostedCommand.

Thanks!
Avatar of SysExpert
SysExpert
Flag of Israel image

1) What version of Notes ?

2) I would do this in Script, rather than  @functions, since it gives you more control.

I hope this helps !
Avatar of kali958

ASKER

I am in ND 7 and my scripting ability is less then my Formula ability - that is why I was trying it in that, but I am open to trying to script it.
Notes does not like to continue running code after the window that contains the code has closed.

You need to move the code to an agent so that it can complete execution after the form closes.

In the action, place this code...
@Command([RunAgent]; "SaveAndNew")

Create an agent named "SaveAndNew" (Hidden, Target=None) and paste this code...
FIELD AllowClose := "1";
FIELD SaveOptions:="1";
FIELD End_Date:=@Now;
FIELD Status :="Archived";
FIELD Person := @If(Person="";@Name([CN];@UserName);@Name([CN];@UserName):Person);
FIELD Action := @If(Action="";"Archived";"Archived":Action);
FIELD ActionDate := @If(ActionDate="";@Now;@Now:ActionDate);
@Command([FileSave]);
@Command([CloseWindow]);
@Command([Compose];"P_2");


NOTE:  Unfortunately, ViewRefreshFields does not return anything, so I removed the first line from this example.
Avatar of kali958

ASKER

It works, but it does not inherit the information on the P_2 form, that is the only hitch, but it did archive the primary document and close it and then open the new P_2 form. I do have the document set to inherit existing information.

Maybe I just need two buttons, one to create and inherit and then one to close the archived document?
SOme sample code that shows how to manipulate fields in a doc via a button
Sub Click(Source As Button)
      Dim doc As notesdocument
      Dim uidoc As notesuidocument
      Dim ws As New notesuiworkspace
      Dim sTime As String, stime1 As String
      Dim evalTotal As Variant, WeekTotal As Variant
      Dim Date2 As  Variant   ,  DT3 As  Variant ' NotesDateTime
      Dim LngDiff As Long, i_loop As Integer
      Dim opts(4) As Variant
      Dim askme As Variant , Brk_time As String, dailybrk As Integer
'
      ' Total the Time fields
      ' V 0.87 6/6/06 added Break Time field.
      
      Set uidoc=ws.currentDocument
      Set doc=uidoc.Document
      WeekTotal =0
      
      opts(0) = "0 Minutes per day"  ' v 0.87 next 12 lines until dailybrk
      opts(1) = "15"
      opts(2) = "30"
      opts(3) = "45"
      opts(4) = "60"
      
      askme = ws.Prompt (PROMPT_OKCANCELLIST, _
      "Daily Break for Meals in minutes", "Select 1.option please:.",       opts(0), opts)
      If Not Isempty (askme) Then
            Brk_time = askme
'            Messagebox "Meal Time: " +       Brk_time
      Else
            Exit Sub
      End If
      Call doc.ReplaceItemValue("M_brk",Brk_time)
      dailybrk= Cint( Brk_time)' part of an hour
'      Messagebox "Meal Time: " +  "," + Cstr(dailybrk)
      
      
      '      deleted code to set WeekTotal value

      Call doc.ReplaceItemValue("tm_Total",WeekTotal)
      uidoc.reload
      
End Sub
See the Design help for methods connected to notesuidocument, and how to close etc.

I hope this helps !
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

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
Re: Can't be done with @Formula language...

Sorry, I left my form name in the agent code, you'll need to replace "SaveAndNew" with "P_2" in the LotusScript part.
Avatar of kali958

ASKER

THANK YOU BILL  - Brilliant as usual, totally worked great!!! That is so what I need it to do.  That way the org. document is archived and the new doc inherits what it needs and the user can submit their changes.  Thanks again