Link to home
Start Free TrialLog in
Avatar of sauce12
sauce12

asked on

Save issue with Rich Text Field

I am executing a script that creates links to "program" documnts within my database, based upon a list of "program" names.  This script is called with an action button.  When this script is executed, any unsaved text that was in a rich text field within the form is deleted.  Any clue what might be causing this?  Thanks in advance for your help!

Here is the script that I am using:

' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     'This script will create links to the programs that are in the ProgramList.
     ' If the program list is blank then no links will be created, and any existing links will be deleted.
     ' If the ProgramList is not blank, then this script will loop through the programList.  
          ' If the the program is in the All Executable Programs view, then a link to that program document will be created.
          ' If the progam is not found in the view, then no link is created, and a message is provided saying that the
          '  program was not found.
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Sub Click(Source As Button)
     Dim ws As NotesUIWorkspace
     Dim uidoc As NotesUIDocument 'current document
     Dim object As Variant
     Dim doc As NotesDocument
     Dim viewdoc As NotesDocument
     Dim ProgList As NotesItem
     Dim rtitem As NotesRichTextItem
     Dim EditMode As Integer
     
     Set ws = New NotesUIWorkspace
     Set uidoc = ws.CurrentDocument
     Set doc = uidoc.Document
     EditMode = uidoc.EditMode
     uidoc.Close
     
     Doevents
     Set ProgList = doc.GetFirstItem("ProgramList")
     If (ProgList.Text <> "") Then 'If program list is blank then links aren't provided
          Set db = doc.ParentDatabase
          Set view = db.GetView( "All Executable Programs" )
          Call view.Refresh
          Call doc.RemoveItem("ProgramLinks") 'deletes current links
          Set rtitem = doc.CreateRichTextItem("ProgramLinks")
          Forall program In doc.GetItemValue( "ProgramList" )
               Set viewdoc = view.GetDocumentByKey( program, True ) 'returns the doc in the view with the matching program Name
               If (viewdoc Is Nothing) Then  
                        'Program doesn't exist in the view , no link is created and a message is provided
                    Call rtitem.AppendText(program & " - This program is not in the list of Executable Programs. Program Name or Program Type may have changed.")
                    Call rtitem.AddNewLine( 1 )
               Else
                       'creates a link to the program document and displays the program name
                    Call rtitem.AppendDocLink( viewdoc, viewdoc.ProgramName(0) )
                    Call rtitem.AppendText(viewdoc.ProgramName(0))
                    Call rtitem.AddNewLine( 1 )
               End If
          End Forall
          doc.Form = "Job"
          Call doc.Save( False, True )
     Else
          'programList is blank, so ProgramLinks should be blanked out as well.  
          Call doc.RemoveItem("ProgramLinks")
     End If
     'reopens the original job document, with the ProgramLinks field updated
     Set uidoc = ws.EditDocument(EditMode, doc)
     If (EditMode) Then Call uidoc.GotoField( "ProgramList" )
     'setting saveOptions to "0" is done so that the user is not prompted to save this document.
     'saveOptions for the currentDocument (uidoc) will be set to "1" when it is reopened
     doc.SaveOptions = "0"
End Sub
Avatar of HemanthaKumar
HemanthaKumar

Your script contains this code,

Call doc.RemoveItem("ProgramLinks") 'deletes current links

which deletes the richtext item totally. So you have to create two seperate rt fields one for input and other to build links. That way you can flush out the links and recreate it.

~Hemanth
Avatar of sauce12

ASKER

Hemanth - Thanks for the response.

I'm not sure if I made myself clear in my explanation of the problem.  

Let me clarify - When I execute this script, I lose any unsaved data in other rich text fields within my form -    Program Links is only updated by this script, it is not editable and it is not used as input.  

If I have unsaved text in any other type of field (not rich text), it seems to be saved when this script is executed.  But, rich text fields lose any unsaved data.

Does that make sense?  Any clue what's going on?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Jean Marie Geeraerts
Jean Marie Geeraerts
Flag of Belgium 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
Sauce12
Ok now I gocha. In your code before uidoc.Close, insert his code uidoc.Save

JM, Yes
Avatar of sauce12

ASKER

Thanks!  I inserted the changed my script as is shown below and it seems to work right now.  Is this what you guys had in mind, or do you see any problems that this might cause?    

Any clue why unsaved text that is non rich text fields was being saved properly before I added this code?  I would think that I would lose data that was saved in any field, but I only seemed to lose unsaved data in rich text fields?

Also, I would assume that I should accept jerrith's answer for this question.  But, Hemanth, I appreciate your help and would like to give you some points as well.  Can I split up the points?  

Set ws = New NotesUIWorkspace
     Set uidoc = ws.CurrentDocument
     EditMode = uidoc.EditMode  
     If (EditMode = True) Then
          Call uidoc.Save 'saves any unsaved text that was in the document before this script is executed    
     End If
     
     Set doc = uidoc.Document
     uidoc.Close
The reason is that rich text is not available in your document unless it was saved, that's all.
If you want to know more about it, just look up rich text problems on the Notes Gold Release forum of Lotus Development Domain : http://www-10.lotus.com/ldd/46dom.nsf?OpenDatabase

You'll see that plenty of people have the same or similar problems when accessing rich text fields using script etc.

Regards,
JM

P.S.: Since my tip pointed out to Hemanth what line needed to be included, does this mean, the points will be split? >:-)
Well, I will always grant the points which I deserve to JM, because he is the best buddy in EE ;-)

JM, note for you. Who knows I might be stealing your points soon ...
Sorry, Hemanth :-)
I didn't think I deserved full credit for this one. I'll be glad to offer you some points in return (I've got plenty of question points I can spent)

JM
Avatar of sauce12

ASKER

Hey guys, I wanted to split the points between the 2 of you, but I didn't know how to give points other than to just accept an answer.  Can I give points without accepting an answer?
It is OK guys.

Note: Sauce, you have contact EE community support center to arrange for split.
We're just goofing, sauce, don't worry. I know Hemanth is my pal, so he won't mind...

In any case if you want to split points for a question, the easiest way is to post a zero-point question in the community support forum with a link to the question for which you want the points to be split.
In the question explain how you want the points to be split and an EE moderator will take of it for you.

Regards and thanks again,
JM