我正在从一个插件(做一些验证)发送一个自定义消息回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;
}在我的表单中,我已经将这个事件处理程序放在new_approval_status的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从空变为空时,这会很好地触发。但它不会反过来触发字符串到空字符串或空字符串或空字符串。
在我的插件中,我尝试过将new_approval_status设置为string.Empty或null,但是事件并没有以这种方式触发。
有什么想法吗?
发布于 2017-04-06 15:55:23
您可以将字段设置为类似于OK的内容。
这还可以保证您的代码工作正常(“字段是空的,因为它应该是空的,或者缺少了什么,而且没有被填充?")
https://stackoverflow.com/questions/43259829
复制相似问题