• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

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!
0
kali958
Asked:
kali958
  • 3
  • 3
  • 3
1 Solution
 
SysExpertCommented:
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 !
0
 
kali958Author Commented:
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.
0
 
Bill-HansonCommented:
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.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
kali958Author Commented:
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?
0
 
SysExpertCommented:
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
0
 
SysExpertCommented:
See the Design help for methods connected to notesuidocument, and how to close etc.

I hope this helps !
0
 
Bill-HansonCommented:
Can't be done with @Formula language alone because there's no way to save the handle to the first form.  It can be done easily with a combination of Formula and LotusScript, though.

Change your form action to this...

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([RunAgent]; "SaveAndNew")


Now change the agent to LotusScript and put this code in the Initialize module...

      Dim ws As New NotesUIWorkspace()
      Dim sess As New NotesSession()
      Dim db As NotesDatabase
      Dim uidocCurrent As NotesUIDocument
      Dim uidocNew As NotesUIDocument
      Dim docCurrent As NotesDocument
      
      Set db = sess.CurrentDatabase
      Set uidocCurrent = ws.CurrentDocument
      Set docCurrent = uidocCurrent.Document
      Set uidocNew = ws.ComposeDocument(db.Server, db.FilePath, "SaveAndNew", , , True)
      Call uidocCurrent.Save()
      Call uidocCurrent.Close(True)


0
 
Bill-HansonCommented:
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.
0
 
kali958Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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