0
私は2つのカスタムワークフローを持っています。一方の出力は他方の出力になります。Dynamics 365 +カスタムワークフロー+エンティティリファレンスでIDとキーの属性を空にできません
私が最初にカスタムワークフローを呼び出し、別のステップでの出力を使用した後、それは私にエラーを与える:第一ワークフローの
'InValid Argument' error - Entity Reference cannot have Id and Key Attributes empty.
コード -
public class RetrieveCaseForUnit : WorkFlowActivityBase
{
#region Input Parameters
[Input("Unit")]
[ReferenceTarget(msdyn_customerasset.EntityLogicalName)]
public InArgument<EntityReference> Unit { get; set; }
#endregion
#region Output Parameters
[Output("Case")]
[ReferenceTarget(Incident.EntityLogicalName)]
public OutArgument<EntityReference> Case{ get; set; }
#endregion
public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
{
try
{
if (crmWorkflowContext == null)
{
throw new ArgumentNullException("crmWorkflowContext is null");
}
crmWorkflowContext.Trace("Getting Unit Input");
EntityReference unitRef = Unit.Get<EntityReference>(executionContext);
if (unitRef == null)
{
crmWorkflowContext.Trace("Error Message : Unit value not provided");
throw new ArgumentNullException("Unit value not provided");
}
EntityReference caseRef = GetCase(crmWorkflowContext, unitRef);
if (caseRef != null)
{
Case.Set(executionContext, caseRef);
}
else
{
Case.Set(executionContext, null);
}
}
catch (Exception ex)
{
throw new InvalidWorkflowException();
}
}
private static EntityReference GetCase(LocalWorkflowContext crmWorkflowContext, EntityReference unitRef)
{
EntityReference caseRef = null;
CrmServiceContext serviceContext = new CrmServiceContext(crmWorkflowContext.OrganizationService);
var caseRecord = (from currentcase in serviceContext.IncidentSet
where currentcase.gsscore_Unitid.Id == unitRef.Id
&& currentcase.gsscore_CaseTypeId.Id == new Guid("3A152B94-D2DF-E711-A94A-000D3A30DB97")
orderby currentcase.CreatedOn descending
select currentcase).FirstOrDefault();
crmWorkflowContext.Trace("Case Record" + caseRecord);
if (caseRecord != null)
caseRef = caseRecord.ToEntityReference();
return caseRef;
}
}
コード第二のワークフローのための -
public class NMSGetWorkOrderForCase : WorkFlowActivityBase
{
#region Input Parameters
[Input(gsscore_nmsmessage.Fields.gsscore_CaseId)]
[ReferenceTarget(Incident.EntityLogicalName)]
public InArgument<EntityReference> Case { get; set; }
#endregion
#region Output Parameters
[Output(gsscore_nmsmessage.Fields.WorkOrder)]
[ReferenceTarget(msdyn_workorder.EntityLogicalName)]
public OutArgument<EntityReference> NMSWorkOrder { get; set; }
#endregion
public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
{
if (crmWorkflowContext == null)
{
throw new ArgumentNullException("crmWorkflowContext is Null");
}
if (Case.Get(executionContext) == null)
{
crmWorkflowContext.UserId = crmWorkflowContext.WorkflowExecutionContext.UserId;
throw new InvalidWorkflowException();
}
crmWorkflowContext.Trace("Start");
Guid caseId = Case.Get<EntityReference>(executionContext).Id;
try
{
CrmServiceContext serviceContext = new CrmServiceContext(crmWorkflowContext.OrganizationService);
var WorkOrderRecord = (from currentworkoder in serviceContext.msdyn_workorderSet
where currentworkoder.msdyn_ServiceRequest.Id == caseId
orderby currentworkoder.CreatedOn descending
select currentworkoder.Id
).ToList().FirstOrDefault();
if (WorkOrderRecord != null)
{
EntityReference workorderRef = new EntityReference(msdyn_workorder.EntityLogicalName, WorkOrderRecord);
NMSWorkOrder.Set(executionContext, workorderRef);
}
}
catch (Exception ex)
{
crmWorkflowContext.TracingService.Trace("Case record does not exist." + crmWorkflowContext.WorkflowExecutionContext.MessageName + ex.Message);
if (crmWorkflowContext.ErrorCode == null)
{
crmWorkflowContext.ErrorCode = ((int)WorkflowActivityErrorCode.NMSGetWorkOrderForCaseError).ToString();
}
crmWorkflowContext.UserId = crmWorkflowContext.WorkflowExecutionContext.UserId;
throw new InvalidWorkflowException();
}
}
}
に変更する必要があります。最初のワークフローが実際に出力を提供していることは確かですか? –
2番目のWFアクティビティを持つ2番目のステップを削除し、1番目のWFアクティビティをデバッグして、caseRecord&caseRefで何が表示されるかを確認するなど、ステップバイステップで行ってみませんか?トレースはすでにあなたにいくつかのアイデアを与えているはずです...? –