近期笔记 0127
try-catch
用于捕捉错误消息,测试实体时不必须。
检验是否在账号下有存在的卡片,已经验证。最神奇的是五个错误都是拼写错误= =。。。
var accountRef = inputData.GetAttributeValue<EntityReference>("infy_bankaccountid");
inputData["infy_name"] = "start to run";
if (accountRef == null)
{
return;
}
var cardCollection = OrganisationService.RetrieveMultiple(
new QueryExpression
{
EntityName = "infy_card",
ColumnSet = new ColumnSet("infy_bankaccountid", "statuscode"),
LinkEntities =
{
new LinkEntity
{
EntityAlias = "bankaccount",
Columns = new ColumnSet(true),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "infy_card",
LinkFromAttributeName = "infy_bankaccountid",
LinkToEntityName = "infy_bankaccount",
LinkToAttributeName= "infy_bankaccountid",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "infy_bankaccountid",
Operator = ConditionOperator.Equal,
Values = { accountRef.Id }
}
}
}
}
}
}).Entities;
if (cardCollection.Any())
{
var accountRecord = OrganisationService.Retrieve("infy_bankaccount", accountRef.Id, new ColumnSet(true));
var opRef = accountRecord.GetAttributeValue<EntityReference>("infy_opportunityid");
if (opRef == null)
{
return;
}
var opRecord = OrganisationService.Retrieve("opportunity", opRef.Id, new ColumnSet(true));
var opClass = opRecord.GetAttributeValue<OptionSetValue>("infy_accountclassificationcode");
if (opClass == null)
{
return;
}
else if (opClass.Value == 1)
{
throw new InvalidPluginExecutionException("A card is already existed in current individual bank account.");
}
}
return;
注释部分检验是否有已经存在的公司,如果存在,则关联到工单上,待验证。
using Microsoft.Xrm.Sdk; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk.Query; using Mck.Xrm.Plugins.AppCode; using Mck.Xrm.Plugins.Services; using System.Text.RegularExpressions; using Microsoft.Xrm.Sdk.Messages; namespace Mck.Xrm.Plugins.Entities { public class FilledRecordPlugin : BaseEntityPlugin { IOrganizationService OrganisationService; ITracingService TracingService; public FilledRecordPlugin(string unsecureConfig, string secureConfig) : base(unsecureConfig, secureConfig) { base.RegisteredEvents.Add(new PluginEvent() { Stage = eStage.PostOperation, MessageName = MessageNames.Update, EntityName = EntityNames.filledrecord, PluginAction = ExecuteCrmPlugin }); base.RegisteredEvents.Add(new PluginEvent() { Stage = eStage.PostOperation, MessageName = MessageNames.Create, EntityName = EntityNames.filledrecord, PluginAction = ExecuteCrmPlugin }); } ///<summary> /// /// </summary> /// public void ExecuteCrmPlugin(IServiceProvider serviceProvider) { using (LocalContext = new LocalPluginContext<Entity>(serviceProvider)) { LocalContext.TracingService.Trace($"connecting..."); LocalContext.TracingService.Trace($"LocalContext.PluginExecutionContext.Stage: {Enum.GetName(typeof(eStage), LocalContext.PluginExecutionContext.Stage)}"); LocalContext.TracingService.Trace($"LocalContext.MessageName: {LocalContext.MessageName}"); LocalContext.TracingService.Trace($"LocalContext.PluginExecutionContext.Depth: {LocalContext.PluginExecutionContext.Depth}"); try { #region service initialization OrganisationService = LocalContext.OrganizationService; TracingService = LocalContext.TracingService; #endregion switch (LocalContext.MessageName) { case Parameters.PluginMessage.Update: UpdatePostOperation(); break; case Parameters.PluginMessage.Create: CreatePostOperation(); break; } } catch (Exception e) { LocalContext.TracingService.Trace("error :" + e.Message); var message = e.InnerException != null ? e.InnerException.Message : string.Empty; message += " - " + e.Message; throw new InvalidPluginExecutionException(message); } } } protected override void CreatePostOperation() { var inputData = LocalContext.TargetEntity; var gstring = inputData.Id; String t = gstring.ToString(); var entityUpdate = new Entity("mck_filledrecord"); entityUpdate["mck_gid"] = t; entityUpdate.Id = inputData.Id; LocalContext.OrganizationService.Update(entityUpdate); } protected override void UpdatePostOperation() { var updateData = LocalContext.TargetEntity; var image = LocalContext.PreImage; var recordType = updateData.GetAttributeValue<OptionSetValue>("mck_recordtype"); var jsonText = updateData.GetAttributeValue<string>("mck_filledjson"); if (!string.IsNullOrEmpty(jsonText)) { FilledRecordService.CustomerInfo customer = FilledRecordService.JsonTool.JsonToObject<FilledRecordService.CustomerInfo>(jsonText) ; var updateCInfo = new Entity("mck_filledrecord"); updateCInfo["mck_clientname"] = customer.ClientName; updateCInfo["mck_istools"] = customer.IsTools; updateCInfo["mck_toolinfo"] = customer.ToolInfo; updateCInfo["mck_datatype"] = customer.DataType; updateCInfo["mck_datainfo"] = customer.DataInfo; updateCInfo["mck_devicetype"] = customer.LaptopType; updateCInfo["mck_additioninfo"] = customer.AdditionInfo; updateCInfo.Id = updateData.Id; LocalContext.OrganizationService.Update(updateCInfo); /*var clientcollection = LocalContext.OrganizationService.RetrieveMultiple( new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("name","accountid"), Criteria = new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression { AttributeName = "name", Operator = ConditionOperator.Equal, Values = { customer.ClientName } }, } } }) .Entities;*/ //var client = clientcollection.FirstOrDefault(); //client.Id = client[""]; if (image.Contains("mck_rticket")) { var regRef = image.GetAttributeValue<EntityReference>("mck_rticket"); var updateTicket = new Entity("mck_incident"); updateTicket.Id = regRef.Id; updateTicket["mck_clientname"] = customer.ClientName; updateTicket["mck_toolsandsolutions"] = customer.ToolInfo; updateTicket["mck_additionalinformation"] = customer.AdditionInfo; updateTicket["mck_othersensitivity"] = customer.DataInfo; //updateTicket["mck_companyname"] = new EntityReference(client.LogicalName, client["accountid"]); switch (customer.DataType) { case "Personal data": updateTicket["mck_informationsensitivity"] = new OptionSetValue(1); break; case "health data": updateTicket["mck_informationsensitivity"] = new OptionSetValue(3); break; case "Other regulated data": updateTicket["mck_informationsensitivity"] = new OptionSetValue(5); break; case "No Idea right now": updateTicket["mck_informationsensitivity"] = new OptionSetValue(6); break; } switch (customer.LaptopType) { case "McK laptop and network": updateTicket["mck_laptop"] = new OptionSetValue(0); break; case "Client laptop and network": updateTicket["mck_laptop"] = new OptionSetValue(1); break; case "Both McK laptop and Client laptop": updateTicket["mck_laptop"] = new OptionSetValue(2); break; case "For restricted environments": updateTicket["mck_laptop"] = new OptionSetValue(3); break; case "No Idea right now": updateTicket["mck_laptop"] = new OptionSetValue(4); break; } switch (customer.IsTools) { case "yes": updateTicket["mck_istool"] = new OptionSetValue(0); break; case "no": updateTicket["mck_istool"] = new OptionSetValue(1); break; } LocalContext.OrganizationService.Update(updateTicket); } } } } }
https://blog.csdn.net/u012664198/article/details/82115492 提示信息js
https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-app/addglobalnotification 全局提示信息js、9.0后有
TLS1.2和D2016+Server2012的解决方案:添加注册表,更改windows默认协议,容后更新。

浙公网安备 33010602011771号