0
我正從一個插件發送一條自定義消息(確實做了一些驗證)回到CRM表單。從插件發送消息以形成對空值不起作用
下面是對前和更新後創建執行我的插件代碼:
//GetAccounts is a simple method to return accounts based in specified crtitias.
//In Update event, it will add an extra filter to exclude the current account...
const string DupeFieldName = "new_approval_status";
if (xrmObjects.PluginContext.PrimaryEntityName == Xrm.Account.EntityLogicalName && xrmObjects.PluginContext.Depth == 1 && (xrmObjects.PluginContext.MessageName == "Update" || xrmObjects.PluginContext.MessageName == "Create"))
{
Entity account;
account = (Entity)xrmObjects.PluginContext.InputParameters["Target"];
if (account.Attributes.Contains("name"))
{
if (GetAccounts(account, xrmObjects.PluginContext.MessageName, "name", account["name"], xrmObjects.Service).Entities.Count > 0)
{
SetDupeMessage(account, Name);
return;
}
}
if (account.Attributes.Contains("websiteurl"))
{
if (GetAccounts(account, xrmObjects.PluginContext.MessageName, "websiteurl", account["websiteurl"], xrmObjects.Service).Entities.Count > 0)
{
SetDupeMessage(account, WebSiteExist);
return;
}
}
if (account.Attributes.Contains("new_linkedin"))
{
if (GetAccounts(account, xrmObjects.PluginContext.MessageName, "new_linkedin", account["new_linkedin"], xrmObjects.Service).Entities.Count > 0)
{
SetDupeMessage(account, LinkedIn);
return;
}
}
account[DupeFieldName] = string.Empty;
}
,設置屬性值的簡單的方法...
private void SetDupeMessage(Entity account, string message)
{
account[DupeFieldName] = message;
account["new_approved"] = false;
}
在我的形式,我已經把這個事件處理程序的onChange
事件new_approval_status
的:
function dupeDetected(context) {
var dupeStatus = Xrm.Page.getAttribute('new_approval_status').getValue();
if (!dupeStatus || dupeStatus == '') {
Notify.remove('duplicateWarning'); //Notify is a library that adds notification at form level...
return;
}
var messageParts = dupeStatus.split('|');
var message = messageParts[1];
var fieldName = messageParts[0];
Notify.add(message, 'ERROR', 'duplicateWarning', null);
};
當new_approval_status
從空變爲空時,這觸發正常。但它不會在其他方式觸發,一個字符串爲空字符串或null。
在我的插件中,我嘗試將new_approval_status
設置爲string.Empty
或null
,但事件不會以這種方式觸發。
任何想法?
我怎麼沒有想到的是超越我。感謝Alex。 –