일부 간단한 계산을 수행하고 특정 조건에 따라 필드를 업데이트하는 플러그인을 작성했습니다. 플러그인이 컴파일되어서 코드를 디버깅 할 수있는 인스턴스를 생성하거나 프로파일 링하는 동안 오류가 발생하지 않습니다. 어쨌든 여기에 더 이상 신경 쓰지 않고 :CRM 플러그인이 필드 값을 변경하거나 업데이트하지 않습니다
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPT.PluginCommon.BaseClasses;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Xrm;
namespace Engage.Crm.Plugins
{
public class VoidPayment : BPTPluginBase
{
bpt_DuesHeader oDuesHeader = new bpt_DuesHeader();
Account org = new Account();
public override void HandleAfterOp()
{
try
{
base.HandleAfterOp();
var crmContext = new XrmServiceContext(this.OrganizationService);
if (this.PluginExecutionContext.MessageName == MessageName.Create ||
this.PluginExecutionContext.MessageName == MessageName.Update)
{
if (this.InputTargetEntity.Attributes.Contains("gih_void"))
{
var Void = (bool) this.InputTargetEntity.Attributes["gih_void"];
var voidReason = (OptionSetValue) this.InputTargetEntity.Attributes["gih_voidreason"];
var totalPayments = (Money) this.InputTargetEntity.Attributes["bpt_TotalPayments"];
var amountBilled =
crmContext.bpt_DuesHeaderSet.Where(
o => o.bpt_DuesHeaderId == this.PluginExecutionContext.PrimaryEntityId)
.ToList()
.Sum(o => o.bpt_TotalAmountBilled == null ? 0 : o.bpt_TotalAmountBilled.Value);
if (Void)
{
this.oDuesHeader.bpt_TotalAdjustments = new Money(amountBilled);
this.oDuesHeader.bpt_TotalAmountBilled =
new Money(oDuesHeader.bpt_TotalAdjustments.Value + totalPayments.Value);
this.oDuesHeader.bpt_Balance = new Money(amountBilled);
if (voidReason.Value == 914020000)
//should be dropped not default option
{
oDuesHeader.gih_terminationdate = DateTime.Now;
}
}
OrganizationService.Update(oDuesHeader);
}
}
}
catch (Exception ex)
{
this.TracingService.Trace(this.ToString() + " {0}", "Exception: {0}", ex.ToString());
throw;
}
}
}
}
죄송합니다. 도움! 플러그인은 사후 작업 및 동기로 등록됩니다. 어떤 통찰력이 도움이 될 것입니다. 그리고 중재자가 코드의 형식을 정하는 데 도움을 줄 수 있다면 크게 향상시킬 수 있습니다. 특정 장소에 4 칸을 추가 할 수 없기 때문입니다.
업데이트가 작동하려면 oDuesHeader에 ID를 설정해야합니다. – Lidaranis
아, 처음에는 속성을 잡아 내 bpt_duesheaderid = new Guide()를 포함시켜야합니까? –
에는 새 GUID가 아닌 ID가 포함됩니다. 업데이트하려는 엔티티의 GUID를 가져옵니다. this.oDuesHeader.Id = whateverentyouwanttoupdate.id의 라인을 따라 뭔가; – Lidaranis