Monday, 1 December 2014

Set the value into the batch model in web event handler

Blackbaud CRM 

I have a scenario that using web event handler, I just made a batch extension for “Revenue Update Batch” . In this batch. If we select REVENUE form search list then it will capture the extension field from data base and set the data into the batch. So for this, see below lines

Private Sub BatchCommitmentUpdateHandler_AfterLoad(sender As Object, e As EventArgs) Handles Me.AfterLoad
        With Me.FieldChangedHandlers
            If FieldIsDefined("REVENUEID") Then
                .Add("REVENUEID", AddressOf GetBenefitDetails)
            End If
        End With
    End Sub


Private Sub GetBenefitDetails(ByVal e As FieldEventArgBase)

        Dim ID = DirectCast(GetValueFromFieldID(e.Model, e.Field.Name, Guid.Empty), Guid)

        If ID.Equals(Guid.Empty) Then Return
        Dim request As New DataFormLoadRequest() With { _
          .FormID = New System.Guid(DATAFORMID_VIEWBENEFITINFO), _
          .RecordID = ID.ToString, _
          .IncludeMetaData = True}

        Dim reply As DataFormLoadReply = Nothing
        Try
            ' DataFormLoad is called to retrieve data from a feature represented by DATAFORMID_FOODITEMINFO. 
            reply = Blackbaud.AppFx.Server.DataFormLoad(request, Me.RequestContext)
        Catch ex As ServiceException When _
                ex.DataFormErrorInfo IsNot Nothing AndAlso _
                ex.DataFormErrorInfo.ErrorCode = DataFormErrorCode.RecordNotFound
            ' The food item doesn't exist
            Return
        End Try
        Dim processedRows As Generic.List(Of Blackbaud.AppFx.XmlTypes.DataForms.DataFormItem)
        Dim collectionValue As New Blackbaud.AppFx.XmlTypes.DataForms.DataFormItem
        If reply Is Nothing Then Return
        Using BatchGridRowUIModel.CreateChangeSuppressor(e.Model)
            '  Once the data is retrieved, the DataFormItem object, which represents the data payload retrieved
            '  from the database, is used within a call to TrySetValuesFromDFI which sets the matching form fields
            '  from the DataFormItem to the batch row. 
            '  The batch row is represented by e.Model.

          Dim benefitList = DirectCast(reply.DataFormItem.Values, Blackbaud.AppFx.XmlTypes.DataForms.DataFormFieldValueSet)
            TrySetValueForFieldID(e.Model, "PROJECTNAME", benefitList.Item("PROJECTNAME").Value)

            Dim benefitArray = DirectCast(benefitList.Item("BENEFITS").Value, Blackbaud.AppFx.XmlTypes.DataForms.DataFormItemArrayValue)
            If benefitArray IsNot Nothing Then
                processedRows = New Generic.List(Of Blackbaud.AppFx.XmlTypes.DataForms.DataFormItem)
                For Each row As Blackbaud.AppFx.XmlTypes.DataForms.DataFormItem In benefitArray.Items
                    collectionValue = New Blackbaud.AppFx.XmlTypes.DataForms.DataFormItem
                    collectionValue.Values.Add("ID", row.Values("ID").Value)
                    collectionValue.Values.Add("BENEFITID", row.Values("BENEFITID").Value)
                    collectionValue.Values.Add("QUANTITY", row.Values("QUANTITY").Value)
                    collectionValue.Values.Add("UNITVALUE", row.Values("UNITVALUE").Value)
                    collectionValue.Values.Add("TOTALVALUE", row.Values("TOTALVALUE").Value)
                    collectionValue.Values.Add("DETAILS", row.Values("DETAILS").Value)
                    collectionValue.Values.Add("SEQUENCE", row.Values("SEQUENCE").Value)
                    collectionValue.Values.Add("TRANSACTIONTOTALVALUE", row.Values("TRANSACTIONTOTALVALUE").Value)
                    collectionValue.Values.Add("BENEFITCURRENCYID", row.Values("BENEFITCURRENCYID").Value)
                    collectionValue.Values.Add("TRANSACTIONCURRENCYID", row.Values("TRANSACTIONCURRENCYID").Value)
                    collectionValue.Values.Add("BASECURRENCYID", row.Values("BASECURRENCYID").Value)
                    processedRows.Add(collectionValue)
                Next
                Dim dataFormItemArrayValue As New Blackbaud.AppFx.XmlTypes.DataForms.DataFormItemArrayValue(processedRows.ToArray)
                Dim dataFormItemValue As New Blackbaud.AppFx.XmlTypes.DataForms.DataFormFieldValue("BENEFITS", dataFormItemArrayValue)
                TrySetValueForFieldID(e.Model, "BENEFITS", dataFormItemValue.Value)
            End If


In above code you would see that after changing REVENUEID, it will cause a handler to invoke and calling any Viewdataform taking REVENUE ID and fetches the extension fields and then it will start to set the standalone field like in above yellow highlighted area . If there will be any collection field then it will use green highlighted area . In this way we can set values in batch model .

No comments:

Post a Comment