Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending names to a list

Status
Not open for further replies.

ThreeDog

Programmer
Nov 4, 2005
2
US
I'm trying to append names in a field but I get illegal use of property and can't figure out why. What I'm trying to do is I have 4 fields with different names in them, I want them all in a Text list field so I can display the same doc in a view multple times. The code I'm having problems with is near the bottom of the function.


Function CreateNewResourceDoc( docRequest As NotesDocument, docResource As NotesDocument, newRequest As String ) As NotesDocument

Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim docAdd As NotesDocument
Dim keyword As String
Dim msg As String
Dim answer As Integer
Dim cnEmp As String

'INITIALIZATION
Set db = s.CurrentDatabase
Set CreateNewResourceDoc = Nothing
answer = IDYES
strVIOwer = "vwAdminITOwner"
Set ITView = DB.GetView( "vwAdminITOwner")
'LOOK FOR DUPLICATE RESOURCE ALREADY ADDED (NOT ON NEW HIRE REQUEST)
If ( ( docRequest.RequestType(0) = "Change" Or docRequest.RequestType(0) = "Transfer" ) And newRequest = "Y" ) Or newRequest <> "Y" Then
cnEmp = GetEmployeeName( docRequest, "Common" )
keyword = cnEmp & SEP & docResource.ResourceType(0) & SEP & docResource.Resource(0)
Set docAdd = GetAddedResourceDocByKey( keyword )
If Not docAdd Is Nothing Then
msg = docResource.ResourceType(0) & " - " & docResource.Resource(0) & " is already a current resource for " & cnEmp & ". Select YES to create a duplicate resource or select NO to cancel creating this resource."
answer = Messagebox ( msg, MB_YESNO + MB_ICONQUESTION, "Warning: Duplicate Resource" )
End If
End If

'CREATE NEW RESOURCE DOCUMENT
If answer = IDYES Then
Set doc = db.CreateDocument
'SET RESOURCE DOCUMENT FIELDS
doc.UNID = doc.UniversalID
doc.Form = "frmResource"
doc.FormTitle = "System"
doc.NewRequest = newRequest
Call UpdateResourceDocWithRequestInfo( doc, docRequest, "Add" )
doc.SysPrimarySystem = docResource.AdminSystemPrimary(0)
doc.SysSystemDescription = docResource.AdminSystemDescription(0)
doc.SysSystemID = docResource.AdminSystemID(0)
groupName = docResource.AdminSystemOwner(0)
ctr = 1
' ============= Add Members of Group ==============
Set ITOwnerDoc= ITView.GetDocumentByKey(Trim(groupName) , True )
If Not ITOwnerDoc Is Nothing Then
Set VMembers = ITOwnerDoc.GetFirstItem( "AdminITOwnerMembers" )
Forall v In VMembers.Values
Call Doc.ReplaceItemValue( "AddSystemTaskAssignee"&ctr, v )

ctr = ctr + 1
End Forall
End If
'==================================================================
Call Doc.FieldAppendText("ITOwnersAll", "," &doc.AddSystemTaskAssignee1)
Call Doc.FieldAppendText("ITOwnersAll", "," &doc.AddSystemTaskAssignee2)
'SAVE THE NEW RESOURCE DOCUMENT
Call doc.ComputeWithForm(False,False)
Call doc.Save( True, False, True )

Set CreateNewResourceDoc = doc
End If

End Function
 
By experience, I can say that Notes does not like to have to concatenate stuff in a function call.
Statements like
Call Doc.ReplaceItemValue( "AddSystemTaskAssignee" & ctr, v )

should ideally be written like
Code:
[i]tempvar[/i] = "AddSystemTaskAssignee" & ctr
Call Doc.ReplaceItemValue( [i]tempvar[/i], v )

Try doing that and tell us if it helped.

Pascal.
 
Keine Kleine Nachtmuzik...

There are 2 basic ways to do this:
1:
EITHER allocate a VARIANT from a field name, in e.g.
MyNames = doc.myNamesToSendTo 'Note: NO (0) in the end!!!

and then use arrayAppend function for appending the other missing names, in.e.g.
MyNames = arrayappend(MyNames, doc.myNameToAdd1(0))
MyNames = arrayappend(MyNames, doc.myNameToAdd2(0))
...

2.
OR use a STRING ARRAY and pre-allocate (This is the BEST if you can't use a field name, since creating multivalue variants is a mind blower)
if you DON't know the number, use this declaration:

Dim myNames() as String
REDIM PRESERVE myNames(0) as string
myNames(0) = doc.myNamesToAdd1(0)
REDIM PRESERVE myNames(1) as string
myNames(1) = doc.myNamesToAdd2(0)

If you DO know the number use this way:

Dim MyNames(3) as string '0-3 = 4 empty strings
MyNames(0) = doc.MyNamesToAdd1(0)
MyNames(1) = doc.MyNamesToAdd2(0)
...etc

I normally prefer to use the first option using a VARIANT, but the other methods is sometimes not to avoid. Concatenating and building lists and strings IS LOTUS NOTES core functions, in case anyone should wonder...

Normally one would do this more elegant in a loop, my intention was to ILLUSTRATE the facts instead of writing ELEGANT code :)

Troodos
 
Ended up doing this and it worked:

Set item = doc.GetFirstItem("ITOwnersAll")
Dim newVals( 1 To 4 ) As String

newVals( 1 ) = doc.ADDSystemTaskAssignee1(0)
newVals( 2 ) = doc.ADDSystemTaskAssignee2(0)
newVals( 3 ) = doc.ADDSystemTaskAssignee3(0)
newVals( 4 ) = doc.ADDSystemTaskAssignee4(0)
Call item.AppendToTextList(newVals)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top