|
Guides (SDK /API) | Technical Reference | BBDN | How-to Documentation |
Code sample project: Custom Pledge Form
Add a reference to the DLL for the Constituent Catalog web API client assembly.
Blackbaud.AppFx.Constituent.Catalog.WebApiClient
To the display form, add a function to retrieve constituent information for the logged in user via the Infinity web API and the Constituent Catalog web API client assembly.
Private Function GetConstituentSummary() Dim ConstituentSummary As New Blackbaud.AppFx.Constituent.Catalog.WebApiClient.ViewForms.Constituent.ConstituentSummaryProfileViewFormData() Dim ConstituentSummaryReq = Blackbaud.AppFx.Constituent.Catalog.WebApiClient.ViewForms.Constituent.ConstituentSummaryProfileViewForm.CreateRequest(Me.API.AppFxWebServiceProvider) ConstituentSummaryReq.RecordID = API.Users.CurrentUser.BackOfficeGuid.ToString ConstituentSummary = Blackbaud.AppFx.Constituent.Catalog.WebApiClient.ViewForms.Constituent.ConstituentSummaryProfileViewForm.LoadData(Me.API.AppFxWebServiceProvider, ConstituentSummaryReq) Return ConstituentSummary End Function
To the form initialization procedure, add logic to populate the Email address field based on information returned from the function. The code should check that there is a GUID for the constituent. This check ensures that the user is linked to a Blackbaud CRM constituent. The condition should also check IsPostBack so that user entered text for TextBoxEmail is not overwritten when the form reloads.
Private Sub InitializeForm()
'If there is a login, get the first and last name for the logged in user.
'Populate the First and Last fields on the form. Disable the First, Middle,
'and Last fields. Otherwise, leave the fields enabled and writeable.
If Not API.Users.CurrentUser.IsAnonymous Then
TextBoxFirst.Text = API.Users.CurrentUser.FirstName
TextBoxLast.Text = API.Users.CurrentUser.LastName
TextBoxFirst.Enabled = False
TextBoxMiddle.Enabled = False
TextBoxLast.Enabled = False
If Not IsPostBack And API.Users.CurrentUser.BackOfficeGuid <> System.Guid.Empty Then
Dim ConstituentSummary As New Blackbaud.AppFx.Constituent.Catalog.WebApiClient.ViewForms.Constituent.ConstituentSummaryProfileViewFormData()
ConstituentSummary = GetConstituentSummary()
TextBoxEmail.Text = ConstituentSummary.EMAILADDRESS
End If
End If
End Sub
To the display form, add a function that adds an email address to a constituent record via the Infinity web API and the Constituent Catalog web API client assembly.
Private Sub AddAdditionalEmail() Dim AddAdditionalEmail As New Blackbaud.AppFx.Constituent.Catalog.WebApiClient.AddForms.EmailAddress.EmailAddressAddFormData() AddAdditionalEmail.ContextRecordID = API.Users.CurrentUser.BackOfficeGuid.ToString AddAdditionalEmail.STARTDATE = System.DateTime.Today AddAdditionalEmail.EMAILADDRESS = TextBoxEmail.Text AddAdditionalEmail.PRIMARY = False AddAdditionalEmail.Save(Me.API.AppFxWebServiceProvider) End Sub
To the procedure for the click action for the Pledge button, add a call to the AddAdditionalEmail procedure for the situation where the user is logged in with a linked login.
Protected Sub ButtonPledge_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonPledge.Click
Try
If Page.IsValid Then
If MyContent.OnlyWriteToCustomPledgeRecord Then
AddCustomPledgeRecord()
ElseIf API.Users.CurrentUser.IsAnonymous Then
AddCustomPledgeRecord()
Else
If API.Users.CurrentUser.BackOfficeGuid = System.Guid.Empty Then
AddCustomPledgeRecord()
Else
AddRevenuePledgeRecord()
AddAdditionalEmail()
End If
End If
End If
'Add close code and direction to a thank you, etc.
Catch ex As Blackbaud.AppFx.WebAPI.AppFxWebServiceException When ex.DataFormErrorInfo IsNot Nothing AndAlso ex.DataFormErrorInfo.ErrorCode = Blackbaud.AppFx.WebAPI.ServiceProxy.DataFormErrorCode.RecordNotFound
End Try
End Sub