Accessing the Parent Form Fields in the UIModel class of a Dataform Extension
I have a dataform extension with a UIModel class, whose parent is the Edit Relationship form in CRM. The purpose of the extension is to transfer field values between the Edit Relationship form and the dataform extension, triggered by certain user events that occur in the form. Does anyone have a snippet I could use showing how to reference the parent form fields from the UIModel code of a dataform extension? C# would be ideal, although VB.NET would be great too.
Comments
-
@Keegan Wade Here is some of the code for a UIModel on an extension used for the out of the box add and edit event forms. It pulls values from the parent UIModel and updates every time they are changed. The null checks look weird but I needed them to prevent a crash. Its been a while but I believe the parent UIModel isn't initialized until a field in the parent form is touched.
using System;
using System.Collections.Generic;
using Blackbaud.AppFx.UIModeling.Core;
namespace MyCatalog.UIModel
{public partial class EventFormExtensionUIModel
{
private Blackbaud.AppFx.UIModeling.Core.DataFormUIModel hostModel;
private string localValue_NAME = string.Empty;
private string localCaption_NAME = string.Empty;
private string localValue_DESCRIPTION = string.Empty;
private string localCaption_DESCRIPTION = string.Empty;
private void EventFormExtensionUIModel_Loaded(object sender, Blackbaud.AppFx.UIModeling.Core.LoadedEventArgs e)
{
hostModel = (Blackbaud.AppFx.UIModeling.Core.DataFormUIModel)this.HostModel;
SetLocalHostModelValues();
}private void EventFormExtensionUIModel_HostModelChanged(object sender, Blackbaud.AppFx.UIModeling.Core.HostModelChangedEventArgs e)
{
if (hostModel == null)
{
hostModel = (Blackbaud.AppFx.UIModeling.Core.DataFormUIModel)this.HostModel;
}if (hostModel != null)
{
if (hostModel is Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)
{
((Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)hostModel).NAME.ValueChanged += HostModel_NAME_ValueChanged;
((Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)hostModel).DESCRIPTION.ValueChanged += HostModel_DESCRIPTION_ValueChanged;
}
else if (hostModel is Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)
{
((Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)hostModel).NAME.ValueChanged += HostModel_NAME_ValueChanged;
((Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)hostModel).DESCRIPTION.ValueChanged += HostModel_DESCRIPTION_ValueChanged;
}//the HostModel often(always?) comes into "Loaded" as not initialized yet. Any action "HostModelChanged"
//add 2nd chance here for Edit form where NAME/DESCRIPTION are not changed or Add form getting a default value.
SetLocalHostModelValues();
}
else
{
if (hostModel is Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)
{
((Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)hostModel).NAME.ValueChanged -= HostModel_NAME_ValueChanged;
((Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)hostModel).DESCRIPTION.ValueChanged -= HostModel_DESCRIPTION_ValueChanged;
}
else if (hostModel is Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)
{
((Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)hostModel).NAME.ValueChanged -= HostModel_NAME_ValueChanged;
((Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)hostModel).DESCRIPTION.ValueChanged -= HostModel_DESCRIPTION_ValueChanged;
}
}
}private void SetLocalHostModelValues()
{
if (hostModel != null)
{
if (hostModel is Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)
{
Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel eventAddHostModel = (Blackbaud.AppFx.Event.UIModel.EventAddFormUIModel)hostModel;
localValue_NAME = eventAddHostModel.NAME.Value;
localCaption_NAME = eventAddHostModel.NAME.Caption;
localValue_DESCRIPTION = eventAddHostModel.DESCRIPTION.Value;
localCaption_DESCRIPTION = eventAddHostModel.DESCRIPTION.Caption;
}
else if (hostModel is Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)
{
Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel eventEditHostModel = (Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)hostModel;
localValue_NAME = eventEditHostModel.NAME.Value;
localCaption_NAME = eventEditHostModel.NAME.Caption;
localValue_DESCRIPTION = eventEditHostModel.DESCRIPTION.Value;
localCaption_DESCRIPTION = ((Blackbaud.AppFx.Event.UIModel.EventEditForm3UIModel)hostModel).DESCRIPTION.Caption;
}localValue_NAME = string.IsNullOrEmpty(localValue_NAME) ? string.Empty : localValue_NAME;
localValue_DESCRIPTION = string.IsNullOrEmpty(localValue_DESCRIPTION) ? string.Empty : localValue_DESCRIPTION;
}
}private void HostModel_NAME_ValueChanged(object sender, Blackbaud.AppFx.UIModeling.Core.ValueChangedEventArgs e)
{
SetLocalHostModelValues();
}private void HostModel_DESCRIPTION_ValueChanged(object sender, Blackbaud.AppFx.UIModeling.Core.ValueChangedEventArgs e)
{
SetLocalHostModelValues();
}
#region "Event handlers"partial void OnCreated()
{
this.Loaded += EventFormExtensionUIModel_Loaded;
this.HostModelChanged += EventFormExtensionUIModel_HostModelChanged;
}}
}
1 -
Thank you @Todd O , that's exactly what I was looking for. The HostModel seemed to always be null, so I couldn't figure out what I was doing wrong to access it properly. But as you pointed out there is some kind of glitch whereby it doesn't get populated until that “HostModelEvent” fires.
1 -
@Todd O, I now also need to change some of the HostModel field values based on certain UI actions that take place in the form. e.g.
hostModel.SENDMAIL.Value = false;
After I make hostmodel field value changes like this, the UI doesn't automatically refresh to reflect the new values. I am searching for a way to trigger it to do this. Ideas?
0 -
@Keegan Wade
If hostModel is the actual type, and not Blackbaud.AppFx.UIModeling.Core.DataFormUIModel like in my sample code, that should work. Maybe the host model isn't loaded yet when your local model event fires?0
Categories
- All Categories
- 6 Blackbaud Community Help
- 206 bbcon®
- 1.4K Blackbaud Altru®
- 394 Blackbaud Award Management™ and Blackbaud Stewardship Management™
- 1.1K Blackbaud CRM™ and Blackbaud Internet Solutions™
- 15 donorCentrics®
- 357 Blackbaud eTapestry®
- 2.5K Blackbaud Financial Edge NXT®
- 646 Blackbaud Grantmaking™
- 561 Blackbaud Education Management Solutions for Higher Education
- 3.2K Blackbaud Education Management Solutions for K-12 Schools
- 934 Blackbaud Luminate Online® and Blackbaud TeamRaiser®
- 84 JustGiving® from Blackbaud®
- 6.4K Blackbaud Raiser's Edge NXT®
- 3.6K SKY Developer
- 242 ResearchPoint™
- 117 Blackbaud Tuition Management™
- 165 Organizational Best Practices
- 238 The Tap (Just for Fun)
- 33 Blackbaud Community Challenges
- 28 PowerUp Challenges
- 3 (Open) Raiser's Edge NXT PowerUp Challenge: Product Update Briefing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports+
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Email Marketing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Gift Management
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Event Management
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Home Page
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Query
- 777 Community News
- 2.9K Jobs Board
- 53 Blackbaud SKY® Reporting Announcements
- 47 Blackbaud CRM Higher Ed Product Advisory Group (HE PAG)
- 19 Blackbaud CRM Product Advisory Group (BBCRM PAG)