//改文章參考了http://www.mamicode.com/info-detail-209704.html
Entity entity = (Entity)context.InputParameters["Target"]; //使用該方式,只有改變了屬性值才可以獲取
//獲得前期事件和后期物體映像
Entity preEntity = (Entity)context.PreEntityImages["Accountname"]; //操作之前
Entity postEntity = (Entity)context.PostEntityImages["Accountstage"];//操作之后
使用該方式的話就不用在插件里面,再取一次物體的其它屬性了,會將屬性值傳入插件
注意的是,在創建,洗掉中不可使用,
可參考該篇文章 https://www.bbsmax.com/A/1O5Eook3z7/
//例子:當前客戶共享團隊 客戶就是指定共享的物體 而團隊就是要求共享的物體
共享呼叫:
EntityReference Record = new EntityReference { Id = entity.Id, LogicalName = entity.LogicalName };
Grant(adminService, (EntityReference)entity["tm_centralize"], Record);
共享方法
//service:服務
//teamOrSystem,:要求共享的物體
//Record:指定共享的物體
private static void Grant_Read(IOrganizationService service, EntityReference teamOrSystem, EntityReference Record)
{
GrantAccessRequest grantAccessRequest = new GrantAccessRequest
{
PrincipalAccess = new PrincipalAccess
{
Principal = teamOrSystem,
AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess //賦予的權限
},
Target = Record,
};
service.Execute(grantAccessRequest);
}
//取消共享
Entity Pusers = service.Retrieve("Account", users.GetAttributeValue<EntityReference>("Accountid").Id, new ColumnSet("tm_centralize"));
RevokeUser(service, entPre.GetAttributeValue<EntityReference>("tm_centralize"), new EntityReference(entPre.LogicalName, entPre.Id));
private void RevokeUser(IOrganizationService service, EntityReference teamOrSystem, EntityReference Record)
{
RevokeAccessRequest revokeAccessRequest = new RevokeAccessRequest
{
Revokee = teamOrSystem,
Target = Record,
};
service.Execute(revokeAccessRequest);
}
//查詢單條
EntityReference entity = (EntityReference)context.InputParameters["Target"];
Entity aaccountTargetEntity = adminService.Retrieve("tm_purchaseamount", entity.Id, new ColumnSet(new string[] { "tm_year", "tm_account" }));
plugin中查詢
string mFetchXml = string.Format(@"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='tm_purchaseamount'>
<attribute name='tm_purchaseamountid' />
<attribute name='tm_name' />
<attribute name='createdon' />
<order attribute='tm_name' descending='false' />
<filter type='and'>
<condition attribute='tm_year' operator='eq' value='https://www.cnblogs.com/jiapinlog/archive/2020/09/28/{0}' />
<condition attribute='tm_account' operator='eq' uiname='=C=' uitype='account' value='https://www.cnblogs.com/jiapinlog/archive/2020/09/28/{1}' />
<condition attribute='statecode' operator='eq' value='https://www.cnblogs.com/jiapinlog/archive/2020/09/28/0' />
</filter>
</entity>
</fetch>
", ((OptionSetValue)entity["tm_year"]).Value.ToString(), ((EntityReference)entity["tm_account"]).Id.ToString());
EntityCollection accountEntites = adminService.RetrieveMultiple(new FetchExpression(mFetchXml));
if (accountEntites.Entities.Count > 0)
{
throw new InvalidPluginExecutionException( ((OptionSetValue)entity["tm_year"]).Value.ToString() + " Year already exists!");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/134799.html
標籤:.NET技术
