Subject: RE: Add value
If you take the value(s) of the field as string(s) and then add the OU to each of them. From there you’d put the array together of all values, remove the existing field and put it back into the document as a new item with the specification of an Authors field.
-
Do a forall loop to grab the items into a text string.
Forall v in doc.fieldname
-
Do the work on each value while in the loop and add it to a variant variable
-
Parse it out using strright, strleft, strrightback, or strleftback to get the value.
-
Or do a ReplaceSubString and replace the [O] with the OU and O values.
-
Put it all back together again and store it in a variant temporary variable with a seperator (“:”, or “;”)
-
After that is all done explode the variant temporary variable. I use a function stored in a Script library to do this. (Provided Below)
-
Remove the existing field by setting it to an item, remove the item.
-
Create a new item on the document and give it a special type (see special types under NotesItem class).
-
Save the document and your done.
Good Luck and enjoy!
Tim Williams
EXPLODE R5 Function:
-
Call it by doing: variant = ExplodeR5( string, “:”, “YES” )
-
Yes is to trim out blanks, no it to keep any blank entries
Here’s the Code:
Function ExplodeR5(mystr As String, comparechar As String, trimYesNo As String) As Variant
'** ParseString
'** This function works the same as @Explode -- WORKS FOR ANY STRING
'** 2004-11-01 -- Added feature to trim out blank values from list if requested as "Yes"
Dim Values List As String, returnval() As String
Dim tempstr As String, tempstrtemp As String
Dim x As Integer, y As Integer, pos As Integer
tempstr = mystr
’ Print “”
x = 0
While Not(tempstr Like "")
pos = Instr(1, tempstr, comparechar)
If (pos = 0) Then
Values(x) = tempstr
tempstr = ""
Else
REM 2004-11-01 -- Added Feature to trim out blank values if requested.
If Ucase(trimYesNo) = "YES" Then
tempstrtemp = Trim(Strleft(tempstr, comparechar))
If Trim(tempstrtemp) = "" Then
x = x - 1
Elseif Trim(Rightbp(tempstrtemp, 1)) = comparechar Then
Values(x) = Trim(Strleft(tempstr, comparechar))
tempstr = ""
Else
Values(x) = Trim(Strleft(tempstr, comparechar))
End If
If tempstr <> "" Then
tempstr = Strright(tempstr, comparechar)
End If
Else
Values(x) = Strleft(tempstr, comparechar)
tempstr = Strright(tempstr, comparechar)
End If
End If
x = x + 1
Wend
If (x >= 1) Then
Redim returnval(x-1)
For y = 0 To x-1
returnval(y) = Values(y)
Next
ExplodeR5 = returnval
Else
Redim returnval(0)
'returnval(0) = mystr
returnval(0) = ""
ExplodeR5 = returnval
End If
End Function
IMPLODE FUNCTION:
-
Call it by ImplodeR5( variant array, “:” )
-
Whatever seperator you used (“:”, or “;”, etc.)
Here’s the Code:
Function ImplodeR5(MyList As Variant, mychar As String) As String
'** Implode
'** Works the same as @Implode
Dim i As Integer
For i = 0 To Ubound(MyList)
If i = 0 Then
ImplodeR5 = MyList(i)
Else
ImplodeR5 = ImplodeR5 + mychar + MyList(i) ' -- User Name will always be last on the list
End If
Next
Exit Function
End Function
REPLACESUBSTRINGR5:
- There is a newer method available in script for this, but I kind of like mine. It works like the @Function.
Here’s the Code:
Function ReplaceSubStringR5(phrase As String, oldStr As String, newStr As String) As String
' ThisFunction searches the string passed in phrase for all
' occurences of the string passed in oldStr. It then replaces
' the oldStr with the specified newStr. If an error occurs,
' a NULL value is returned ("").
On Error Goto ErrorHandler
Dim begin As Integer
Dim found As Integer
Dim newPhrase As String
begin = 1
If oldStr = "" Or phrase = "" Then Goto TheEnd
found = Instr(begin, phrase, oldStr, 1)
While (found > 0)
begin = found + Len(oldStr)
newPhrase = Left$(phrase, (found - 1)) & newStr & _
Right$(phrase, Len(phrase) - (found + (Len(oldStr) - 1)))
phrase = newPhrase
found = Instr(begin, phrase, oldStr, 1)
Wend
ReplaceSubStringR5 = phrase
Exit Function
ErrorHandler:
Print "ReplaceSubStringR5: " & Trim$(Str$(Err)) & ": " & Error$
Resume TheEnd
TheEnd:
ReplaceSubStringR5 = phrase
End Function