AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 21.01.2009, 10:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,617 / 848 (80) +++++++
Регистрация: 28.10.2006
mscrm4ever: CRM 4.0 Creating Interactive Plug-ins
Источник: http://mscrm4ever.blogspot.com/2009/...-plug-ins.html
==============






The Plug-ins model is a truly robust mechanism which makes it very easy to enforce business rules and control the way your organization data flows.
However, this model does have a few limitations. One in specific which I find very annoying is the fact you can’t return interactive html to the user and must be satisfied with static textual information. I truly believe ms should consider changing this behavior in their next version.


In order to overcome this limitation I made a small yet unsupported modification to the error dialog page that pops up when you throw an
Invalid plug-in exception. The dialog resides in inside /CRMWeb/_common/error/dlg_error.aspx


In order to make the dialog support HTML messages I added the following function that transforms the ErrorMessage Text to HTML and also added an onload event in the html body tag.



function unsupported()
{
var ErrorMessage = document.getElementById("ErrorMessage");
ErrorMessage.innerHTML = ErrorMessage.innerText;
}







To test this “theory” I created a simple duplicate detection check on the contact entity first and last name.
If a duplicate is found, I construct an HTML error message with a link to the duplicate record and
pass it as an InvalidPluginExecutionException parameter.


To test this out simply register the plug-in on the contact pre create / update event.




using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Query;

namespace TestPlugin
{
public class DuplicateHandler : IPlugin
{
#region IPlugin Members

public void Execute(IPluginExecutionContext context)
{
if (context.InputParameters.Properties.Contains(ParameterName.Target))
{
#region Check Duplicate Contact [FirstName LastName]

DynamicEntity contact = context.InputParameters.Properties[ParameterName.Target] as DynamicEntity;
String firstName = String.Empty;
String lastName = String.Empty;

if (contact.Properties.Contains("firstname"))
{
firstName = contact.Properties["firstname"].ToString();
}

if (contact.Properties.Contains("lastname"))
{
lastName = contact.Properties["lastname"].ToString();
}


QueryExpression query = new QueryExpression(context.PrimaryEntityName);
query.ColumnSet.AddColumn(context.PrimaryEntityName + "id");

ConditionExpression firstCondition = new ConditionExpression();
firstCondition.AttributeName = "firstname";
firstCondition.Operator = ConditionOperator.Equal;
firstCondition.Values = new object[] { firstName };

ConditionExpression lastCondition = new ConditionExpression();
lastCondition.AttributeName = "lastname";
lastCondition.Operator = ConditionOperator.Equal;
lastCondition.Values = new object[] { lastName };

FilterExpression whereFilter = new FilterExpression();
whereFilter.Conditions.Add(firstCondition);
whereFilter.Conditions.Add(lastCondition);
whereFilter.FilterOperator = LogicalOperator.And;

query.Criteria = whereFilter;

ICrmService Service = context.CreateCrmService(true);
BusinessEntityCollection resultCollection =
(BusinessEntityCollection)Service.RetrieveMultiple(query);

#endregion

#region Retrieve Duplicate HTML

if (resultCollection.BusinessEntities.Count > 0)
{
contact dupContact = resultCollection.BusinessEntities[0] as contact;

String linkStyle = "text-decoration:underline;color:blue;";

String contactUrl = String.Format(
"{3} {4}" ,
linkStyle,
context.OrganizationName,
dupContact.contactid.Value.ToString(),
firstName,
lastName
);

String errorMessage = String.Format("Duplicate Contact: {0}",contactUrl);

throw new InvalidPluginExecutionException(errorMessage);

}

#endregion
}

#endregion
}
}
}


Источник: http://mscrm4ever.blogspot.com/2009/...-plug-ins.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
mscrm4ever: CRM 4.0 Concatenating Fields Plug-In Blog bot Dynamics CRM: Blogs 0 14.02.2009 14:05
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
Microsoft Dynamics CRM Team Blog: Part Deux: Storing Configuration Data for Microsoft Dynamics CRM Plug-ins Blog bot Dynamics CRM: Blogs 0 15.11.2008 09:07
Microsoft Dynamics CRM Team Blog: Microsoft Dynamics CRM Plug-in Template for Visual Studio Blog bot Dynamics CRM: Blogs 0 27.10.2008 23:05
Microsoft Dynamics CRM Team Blog: Storing Configuration Data for Microsoft Dynamics CRM Plug-ins Blog bot Dynamics CRM: Blogs 0 24.10.2008 22:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 23:55.