?
Solved

Save current document and open a new document

Posted on 2007-10-10
9
Medium Priority
?
271 Views
Last Modified: 2013-12-18
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
Comment
Question by:kali958
  • 3
  • 3
  • 3
9 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 20049517
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
 

Author Comment

by:kali958
ID: 20049527
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
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20050277
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
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.

 

Author Comment

by:kali958
ID: 20050739
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
 
LVL 63

Expert Comment

by:SysExpert
ID: 20050945
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
 
LVL 63

Expert Comment

by:SysExpert
ID: 20050962
See the Design help for methods connected to notesuidocument, and how to close etc.

I hope this helps !
0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 1000 total points
ID: 20051230
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
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20051247
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
 

Author Comment

by:kali958
ID: 20051285
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  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…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 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