views:

987

answers:

2

Good day,

I'll start by saying I work for a small company and have no official training in Notes everything I know I've learned buy trial and error & using other peoples codes.

Application: We have a purchase order database that has been running for a very long time and threw the ages people put in supplier names diffirently. Now I found a code that goes into the selected forms and changes the field values which is exactly what I need the only problem is it's single line. The field I want to update have about 5 text lines (Company name, Tel No etc..) and the original programer put all off the info in one field.

Question: Is there a way in the script linked below how I can make each prompt input go into a diffirent line.I tried a few thing and I think I may be missing something obvious.(If I try chr(10);chLv all I get is either the 2 values next to each other or get them seperated by a comma)

` Sub Initialize Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim prompt As String Dim fieldName As String Dim fieldValue As String Dim dataTypes As Variant Dim thisDataType As String Dim fieldValues As Variant Dim newFieldValues As Variant Dim db As NotesDatabase Dim coll As NotesDocumentCollection Dim i As Integer Dim doc As NotesDocument Dim item As NotesItem

prompt = "Please enter the name of the field to be updated"
fieldName = ws.Prompt(3, "Enter Field Name", prompt, "")
If fieldName = "" Then Exit Sub
If Instr(fieldName, " ") <> 0 Then
    prompt = "Error! Field Names can't have spaces!"
    Msgbox prompt, 16, "Error"
    Exit Sub
End If
prompt = "Please enter the new value. For multiple values, separate with a colon."
Value1 =ws.Prompt(3, "Enter Field Value", prompt, "")
Value2= ws.Prompt(3, "Enter Field Value", prompt, "")   
Fieldvalue=value1 + Chr(10) +value2

Redim dataTypes(5) As String
dataTypes(0) = "Text"
dataTypes(1) = "Number"
dataTypes(2) = "Date"
dataTypes(3) = "Readers"
dataTypes(4) = "Authors"
dataTypes(5) = "DELETE THIS FIELD"
prompt = "Choose the data type of the value(s)"
thisDataType = ws.Prompt(4, "Choose Data Type", prompt, dataTypes(0), dataTypes)
If thisDataType = "" Then Exit Sub

Set db = session.CurrentDatabase
Set coll = db.UnprocessedDocuments
fieldValues = Evaluate({@Explode("} & fieldValue & {"; ":")})
Select Case thisDataType
Case dataTypes(0) : Redim newFieldValues(Ubound(fieldValues)) As String
Case dataTypes(1) : Redim newFieldValues(Ubound(fieldValues)) As Double
Case dataTypes(2) : Redim newFieldValues(Ubound(fieldValues)) As Variant
Case dataTypes(3) : Redim newFieldValues(Ubound(fieldValues)) As String
Case dataTypes(4) : Redim newFieldValues(Ubound(fieldValues)) As String
End Select
For i = Lbound(fieldValues) To Ubound(fieldValues)
    Select Case thisDataType
    Case dataTypes(0) : newFieldValues(i) = Trim(fieldValues(i))
    Case dataTypes(1) : newFieldValues(i) = Val(fieldValues(i))
    Case dataTypes(2) : newFieldValues(i) = Cdat(fieldValues(i))
    Case dataTypes(3) : newFieldValues(i) = Trim(fieldValues(i))
    Case dataTypes(4) : newFieldValues(i) = Trim(fieldValues(i))
    End Select
Next
Set doc = coll.GetFirstDocument
While Not doc Is Nothing
    If thisDataType = "DELETE THIS FIELD" Then
        If doc.HasItem(fieldName) Then Call doc.RemoveItem(fieldName)
    Else
        Call doc.ReplaceItemValue(fieldName, newFieldValues)
        If thisDataType = dataTypes(3) Or thisDataType = dataTypes(4) Then
            Set item = doc.GetFirstItem(fieldName)
            If thisDataType = dataTypes(3) Then item.IsReaders = True
            If thisDataType = dataTypes(4) Then item.IsAuthors = True
        End If
    End If
    Call doc.Save(True, False)
    Set doc = coll.GetNextDocument(doc)
Wend

End Sub '

Sorry for the long post but wasn't sure what is needed. First time posting for help but I'm scared I missed something opposite.

Francois

A: 

Hi,

To display the values in separate lines within a field you have to open the field properties and on the 3rd Tab make sure the option "Display separate values with" is set to "New Line".

On another note the split function in lotusscript is the equivalent to the @explode, so this line:

fieldValues = Evaluate({@Explode("} & fieldValue & {"; ":")})

can be modified to the following:

fieldValues = split(fieldValue, ":")

Hope that helps.

Carlos
Thanks for taking the time to reply. Would there maybe be a way that I can change the field properties using the same script ? (The display separate values in new line). The reason being is these forms I need to change goes back to about 1992 and since then they have changed the format of the forms allot but kept the "Store form in document" setting on, so the only way I can change those field settings is by using a global database form template update and I'm not sure what types of havoc it will do.Thanks againFrabcois
Francois
Ouch. Sounds like you're already down the route of a horribly unmaintainable app. At somestage someone is going to have to bite the bullet and refactor.
kerrr
+1  A: 

If you don't care that the values are not actually seperate, but are in fact a single string seperated by newlines, you could try evaluating Field fieldname:=@implode(fieldname, @newline) There was a bug (now fixed) in the java api where using java newline chars \n did not translate through to the stored value. Having the field set via evaluating an @formula was a workaround.

It's possible (?) that there is a platform specific issue to using Chr(10). Have you tried using Chr(13) & Chr(10)? You coudl also try evaluating @newline and using what that gives you.

kerrr
Thanks for for the advice. I'm still busy playing around with it, it take a lot of trial and error for me to get stuff done. The funny thing is the forms which had multiple fields converted easily it's just the other half where they decided to stick everything in one field. If I may bother with one idea I had is it possible to write a new field into a document like this ( a document that has been stored in the form)?
Francois
In Notes there is a fundamental difference between a Field on a Form and an Item on a Document. These two things are related but often conflated. You should try and always think about them as distinct things. Unless there is a good architectural reason to have Forms stored on the document you should look at getting rid of them. If you are needing to go and update stored forms, then there is something very wrong.
kerrr
Thanks again for taking the time to answer/explain apriciate it and understand it allot better now.I'm also 99% there with my script actualy thought I had it. Using Chr(10) and Chr(13) at the right place now changes the value in multi lines but when you double click on it it reverts to the old value. Thanks again for all you help.
Francois