Beispiel #1
0
        public static Guid ApplyWorkFlow(Entity entity, string workflowName, InputArgumentCollection args = null, CrmConnection connection = null)
        {
            EntityCollection col = RetrieveByAttribute("workflow", "name", workflowName);

            if (col.Entities.Count != 1)
            {
                throw new ArgumentException(string.Format("{0} workflows with the name {1} exist. Expected 1.", col.Entities.Count, workflowName), "workflowName");
            }
            return(ApplyWorkFlow(entity, col.Entities.First().Id, args, connection));
        }
Beispiel #2
0
        public static Guid ApplyWorkFlow(Entity entity, Guid workflowId, InputArgumentCollection args = null, CrmConnection connection = null)
        {
            ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
            {
                EntityId       = entity.Id,
                WorkflowId     = workflowId,
                InputArguments = args
            };
            ExecuteWorkflowResponse response = Execute <ExecuteWorkflowRequest, ExecuteWorkflowResponse>(request, connection);

            return(response.Id);
        }
Beispiel #3
0
        /// <summary>
        /// Inspects the arguments supplied on the user's query document, merges them with those defaulted from the graph field itself
        /// and applies variable data as necessary to generate a single unified set of input arguments to be used when resolving a field of data.
        /// </summary>
        /// <param name="argumentContainer">The field selection.</param>
        /// <param name="querySuppliedArguments">The supplied argument collection parsed from the user query document.</param>
        /// <returns>Task&lt;IInputArgumentCollection&gt;.</returns>
        private IInputArgumentCollection CreateArgumentList(
            IGraphFieldArgumentContainer argumentContainer,
            IQueryInputArgumentCollection querySuppliedArguments)
        {
            var collection   = new InputArgumentCollection();
            var argGenerator = new ArgumentGenerator(_schema, querySuppliedArguments);

            foreach (var argument in argumentContainer.Arguments)
            {
                var argResult = argGenerator.CreateInputArgument(argument);
                if (argResult.IsValid)
                {
                    collection.Add(new InputArgument(argument, argResult.Argument));
                }
                else
                {
                    _messages.Add(argResult.Message);
                }
            }

            return(collection);
        }
Beispiel #4
0
        public static void ApplyAction(this Entity entity, KeyValuePair <string, string> action)
        {
            string[] actionArgs = action.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            switch (action.Key.ToUpper())
            {
            case "APPLYWORKFLOW":
                InputArgumentCollection workflowArgs = null;
                if (actionArgs.Length > 1)
                {
                    workflowArgs = new InputArgumentCollection();
                    for (int i = 1; i < actionArgs.Length; i++)
                    {
                        string[] workflowArg = actionArgs[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        workflowArgs.Add(workflowArg[0], workflowArg[1]);
                    }
                }
                Guid g;
                if (Guid.TryParse(actionArgs[0], out g))
                {
                    XrmCore.ApplyWorkFlow(entity, g, workflowArgs);
                }
                else
                {
                    XrmCore.ApplyWorkFlow(entity, actionArgs[0], workflowArgs);
                }
                break;

            case "ADDTOMARKETINGLIST":
            case "REMOVEFROMMARKETINGLIST":
                bool remove = action.Key.Equals("REMOVEFROMMARKETINGLIST", StringComparison.OrdinalIgnoreCase);
                for (int i = 0; i < actionArgs.Length; i++)
                {
                    Entity list = XrmCore.RetrieveByAttribute("list", "listname", actionArgs[i], new ColumnSet("listid")).Entities.FirstOrDefault();
                    if (list == null)
                    {
                        throw new ArgumentException(string.Format("The Marketing list {0} could not be found", actionArgs[0]));
                    }
                    else
                    {
                        if (remove)
                        {
                            XrmMarketing.RemoveFromMarketingList(entity.Id, list.Id);
                        }
                        else
                        {
                            XrmMarketing.AddToMarketingList(new Guid[] { entity.Id }, list.Id);
                        }
                    }
                }
                break;

            case "ASSIGN":
                FilterExpression filter = new FilterExpression(LogicalOperator.Or);
                filter.AddCondition("fullname", ConditionOperator.Like, new object[] { actionArgs[0] });
                filter.AddCondition("internalemailaddress", ConditionOperator.Like, new object[] { actionArgs[0] });
                Entity owner = XrmCore.RetrieveByFilter("systemuser", filter, new ColumnSet("systemuserid")).Entities.FirstOrDefault();
                if (owner == null)
                {
                    throw new ArgumentException(string.Format("The System user with the name or email {0} could not be found", actionArgs[0]));
                }
                else
                {
                    AssignRequest request = new AssignRequest()
                    {
                        Assignee = owner.ToEntityReference(),
                        Target   = entity.ToEntityReference()
                    };
                    XrmCore.Execute <AssignRequest, AssignResponse>(request);
                }
                break;

            default:
                break;
            }
        }