private Action FormatAction(Action originalAction) { Action formattedAction = new Action(originalAction.ActionName); foreach (var attribute in originalAction) { var obj = attribute.Value; if (obj != null) { Type objType = obj.GetType(); if (objType == typeof(EntityReference)) { EntityReference eRef = obj as EntityReference; string idname = eRef.LogicalName == "phonetocaseprocess" ? "businessprocessflowinstanceid" : $"{eRef.LogicalName}id"; formattedAction[attribute.Key] = new Dictionary <string, string> { { idname, eRef.Id.ToString() }, { "@odata.type", $"Microsoft.Dynamics.CRM.{eRef.LogicalName}" } }; } else { formattedAction[attribute.Key] = attribute.Value; } } else { formattedAction[attribute.Key] = attribute.Value; } } return(formattedAction); }
public void SetProcess() { Action action = new Action("SetProcess") { ["Target"] = new EntityReference("incident", new Guid("00868FC6-1D67-E811-A95C-000D3AD1C598")), ["NewProcess"] = new EntityReference("workflow", new Guid("0FFBCDE4-61C1-4355-AA89-AA1D7B2B8792")), ["NewProcessInstance"] = new EntityReference("phonetocaseprocess", new Guid("D0B3D3CC-2367-E811-A962-000D3AD1C0D2")) }; client.Execute(action); }
public void Execute(Action action) { RestApiResponse <Entity, Exceptions> response = PostAsync <Action, Entity, Exceptions>(FormatAction(action), action.ActionName).Result; }