Monday, 1 December 2014

Add a Link button on Viewdataform

Blackbaud CRM 

If i have a Event page and in the top of the page, we have summary view form. In this View form, i need to add a link which will redirect to the selected event . See below image for some help

Now if you see i have added a Linkbutton which is not included in OOB .And the scenario is to add this linkbutton into child event not in main event . If you will search for any event then if that event is Main event then this link button and its label would be visible off else it will show in child event .

First of all, i added a Viewdataformspec and in this spec, i used below Stored Procedure

@ID uniqueidentifier,
@DATALOADED bit = 0 output,
@PARENTEVENTID uniqueidentifier = null output,
  @PARENTEVENTNAME nvarchar(255) = null output
set nocount on;

-- be sure to set this, in case the select returns no rows
set @DATALOADED = 0;

-- populate the output parameters, which correspond to fields on the form.  Note that
-- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system
-- will display a "no data loaded" message.
     @DATALOADED = 1,
from dbo.EVENT as E
  left join dbo.EVENT ME on ME.ID = E.MAINEVENTID
where E.ID = @ID

return 0;

And in form field i just include both the PARENTEVENTID and PARENTEVENTNAME. I have also added UI Action, see below lines for UI Action

      <common:UIAction ActionID="GOTOPARENTEVENTNAME" Caption="Parent Event">

In the bottom of the page to extend the existing summary view form, i have added a standard code,

<common:DataFormExtension DataFormInstanceID="060f714a-8bf4-4bcc-90a3-a192bb9b28de"  RenderStyle="AfterParent" TabCaption="Parent Information" />

Now after this, UI model generated . In HTML pafe generated in UI Model, i have made some alteration. see below HTML code. I am just pasting the main table entry from HTML page

        <tr id="#MAP#PARENTEVENTNAME_container">
                <span id="#MAP#PARENTEVENTNAME_caption" class="bbui-forms-captionlight"> </span>

                <a id="#MAP#GOTOPARENTEVENTNAME_action"></a>
        <tr style="display:none">

                <!--<button id="#MAP#GOTOPARENTEVENTNAME_action"></button>-->

If you see in above HTML, i have commented out the button tag and take the UI Action button Id and replace with PARENTEVENT and also replace the SPAN tag with the Anchor tag. See red highlighted text area in above HTML.

After that i have made some changes in VB class .Please see the below mentioned lines

 Private Sub EventSummaryExtViewCustomDataFormUIModel_Loaded(ByVal sender As Object, ByVal e As Blackbaud.AppFx.UIModeling.Core.LoadedEventArgs) Handles Me.Loaded
        If _parenteventid.Value <> Guid.Empty Then
            _gotoparenteventname.Caption = _parenteventname.Value
            _gotoparenteventname.Visible = False
            _parenteventname.Visible = False
        End If

    End Sub

    Private Sub _gotoparenteventname_InvokeAction(sender As Object, e As InvokeActionEventArgs) Handles _gotoparenteventname.InvokeAction
        'Navigate to Event page with parameter parent event id
        NavigateToPage(Guid.Parse("9988b807-97b2-434c-8be1-bbee6b944b2c"), Me._parenteventid.Value.ToString())
    End Sub

There are 2 events above, first one is load event in which i decided whether the event is main event or child event and based on condition it will decides its visibility . In second event which is UI Action button event handler. I have used "NavigateToPage" method which takes the page Id and Context Id to take the user into the selected page.

No comments:

Post a Comment