/ Forums / Advansys Formativ / Creating Solutions with Formativ / Custom Fields / Reply To: Custom Fields
I created my own class to handle adding custom fields to a draft message using the Novell Object API. I hope the following code is of some assistance to you.
quote:
‘ Custom Fields
Set myFields = New CCustomFields
If myFields.AttachToMsg(DraftMsg) Then
Call myFields.SetFieldValue(FIELD_ACCOUNT, NewMsgDlg.eAccount.Text, fgwString)
Call myFields.SetFieldValue(FIELD_PROJDESC, NewMsgDlg.eProjectDesc.Text, fgwString)
End If
Here is the full code of how I send a message with custom fields:
'------------------------------------------------------------------------------- ' Send the message '------------------------------------------------------------------------------- Function SendMessage(ByVal RecipientEmail, ByVal CCEmail, ByVal BCEmail, ByVal Subject, ByVal BodyText, ByVal AttachList) Dim i, DraftMsg, SentMsg, myFields SendMessage = "" ' Use the Object API to create a new draft email message Set DraftMsg = GroupWise.Account.Mailbox.Messages.Add("GW.MESSAGE.MAIL", fgwDraft) ' Subject and Body DraftMsg.Subject = Subject DraftMsg.BodyText.PlainText = BodyText ' Recepient Field If RecipientEmail.Count > 0 Then For i = 0 To RecipientEmail.Count - 1 Call DraftMsg.Recipients.Add(RecipientEmail.EmailAddress(i), "NGW", fgwTo) Next End If ' CC Field If CCEmail.Count > 0 Then For i = 0 To CCEmail.Count - 1 Call DraftMsg.Recipients.Add(CCEmail.EmailAddress(i), "NGW", fgwCC) Next End If ' BC Field If BCEmail.Count > 0 Then For i = 0 To BCEmail.Count - 1 Call DraftMsg.Recipients.Add(BCEmail.EmailAddress(i), "NGW", fgwBC) Next End If ' Attachments Dim sFilename For i = 0 to AttachList.Items.Count - 1 sFilename = Toolbox.NormalizeFilePathLoc(AttachList.Items(i).SubItems(0)) Utilities.Trace "Attach sFilename " & sFilename DraftMsg.Attachments.Add(sFilename) Next ' Custom Fields Set myFields = New CCustomFields If myFields.AttachToMsg(DraftMsg) Then Call myFields.SetFieldValue(FIELD_ACCOUNT, NewMsgDlg.eAccount.Text, fgwString) Call myFields.SetFieldValue(FIELD_PROJDESC, NewMsgDlg.eProjectDesc.Text, fgwString) End If ' Send the message and return the message ID Set SentMsg = DraftMsg.Send If not SentMsg is nothing then Utilities.Trace "SentMsg.MessageID=" & SentMsg.MessageID SendMessage = SentMsg.MessageID Set SentMsg = Nothing End If Set DraftMsg = Nothing Set myFields = Nothing End Function
And here is my class to handle custom fields:
'------------------------------------------------------------------------------- ' ' CCustomFields Class ' ' Methods: ' AttachToMsg(Msg) - Attach to the current message. Return a boolean indicating success ' SetFieldValue(TheName, TheValue, TheType) - Store TheValue in TheName field ' GetFieldValue(TheName, TheType) - Return the value currently stored in the custom field of TheName ' ' Use: ' Dim iFields ' Set iFields = New CCustomFields ' iFields.AttachToMsg(Msg) ' MsgBox (iFields.GetFieldValue(FIELD_NAME,1) ' Call iFields.SetFieldValue(FIELD_NAME,Value,1) ' ' TheType is of eFieldType ' fgwString 1 String ' fgwNumeric 2 Numeric (32 bits) ' fgwDate 3 Date ' fgwBinary 4 Binary ' fgwReserved 5 Reserved ' ' ' This class contains methods designed to make access to GroupWise message ' custom fields simpler. Use the AttachToMsg to connect to the message we ' want to write to/read from, then use the SetFieldValue()/GetFieldValue() ' methods to read/write the data ' '------------------------------------------------------------------------------- class CCustomFields Private iMsg Private Sub class_terminate set iMsg = nothing End sub Public Function AttachToMsg(ByRef Msg) If Toolbox.SkipErrors Then On Error Resume Next AttachToMsg = false set iMsg = Msg if iMsg is Nothing then exit function else AttachToMsg = true end if Toolbox.OnErrorCheckUp("AttachToMsg") end function Public Sub SetFieldValue(ByVal TheName, ByVal TheValue, ByVal TheType) If Toolbox.SkipErrors Then On Error Resume Next If Len(TheName) = 0 Then Exit Sub If Not FieldExists(TheName, TheType) Then Call GroupWise.Account.FieldDefinitions.Add(TheName, TheType) End If Call iMsg.Fields.Add(TheName, TheType, TheValue) Toolbox.OnErrorCheckUp("SetFieldValue") End Sub Public Function GetFieldValue(TheName, TheType) If Toolbox.SkipErrors Then On Error Resume Next Dim iField If iMsg.Fields.Count > 0 Then Set iField = iMsg.Fields.Item(TheName, TheType) GetFieldValue = iField.Value Else GetFieldValue = "" End If Toolbox.OnErrorCheckUp("GetFieldValue") End Function Private Function FieldExists(TheName, TheType) If Toolbox.SkipErrors Then On Error Resume Next Dim FieldObj Dim FieldDefs Set FieldDefs = GroupWise.Account.FieldDefinitions Set FieldObj = FieldDefs.Item(TheName,TheType) If IsObject(FieldObj) Then FieldExists = TRUE Else FieldExists = FALSE End If Toolbox.OnErrorCheckUp("FieldExists") Set FieldObj = Nothing Set FieldDefs = Nothing End function End Class ' ' End CCustomFields Class '-------------------------------------------------------------------------------
Please note: You cannot use this class as is, because there are other classes involved that I have not presented.