Example #1
0
        private void BrowseUser()
        {
            var form = new CrmUserPickerForm(new CrmAccess(Service));

            if (form.ShowDialog() == DialogResult.OK)
            {
                foreach (Guid userId in form.SelectedUsers.Keys)
                {
                    textBox_UserID.Text = form.SelectedUsers[userId];
                    textBox_UserID.Tag  = userId;
                }
            }
        }
Example #2
0
        private void BrowseUser()
        {
            var form = new CrmUserPickerForm(new CrmAccess(Service, ConnectionDetail));

            if (form.ShowDialog() == DialogResult.OK)
            {
                textBox_UserID.Text = form.SelectedUser.Name;
                textBox_UserID.Tag  = form.SelectedUser;
                //foreach (Guid userId in form.SelectedUsers.Keys)
                //{
                //    textBox_UserID.Text = form.SelectedUsers[userId];
                //    textBox_UserID.Tag = userId;
                //}
            }
            else
            {
                textBox_UserID.Text = string.Empty;
                textBox_UserID.Tag  = null;
            }
        }
        private void TransformOwner(TransferType type, UserControl ctrl)
        {
            if (record.LogicalName == "userquery")
            {
                EntityReference targetReference;
                string          name;
                var             sourceOwnerRef = record.GetAttributeValue <EntityReference>("ownerid");

                if (sourceOwnerRef.LogicalName == "systemuser")
                {
                    var sourceUser = sourceService.Retrieve("systemuser", sourceOwnerRef.Id, new ColumnSet("domainname", "fullname"));
                    name = sourceUser.GetAttributeValue <string>("domainname");
                    var fullname = sourceUser.GetAttributeValue <string>("fullname");

                    if (type != TransferType.Same)
                    {
                        var cupDialog = new CrmUserPickerForm(targetService, record.GetAttributeValue <string>("name"), fullname, name);
                        if (cupDialog.ShowDialog(ctrl) != DialogResult.OK)
                        {
                            throw new Exception("It is mandatory to select a target user");
                        }

                        targetReference = cupDialog.SelectedUser.ToEntityReference();
                    }
                    else
                    {
                        // Let's find the user based on systemuserid or domainname
                        var targetUser = targetService.RetrieveMultiple(new QueryExpression("systemuser")
                        {
                            Criteria = new FilterExpression(LogicalOperator.Or)
                            {
                                Conditions =
                                {
                                    new ConditionExpression("domainname",                                                     ConditionOperator.Equal,
                                                            name ?? "dummyValueNotExpectedAsDomainNameToAvoidSystemAccount"),
                                    new ConditionExpression("systemuserid",                                                   ConditionOperator.Equal,sourceOwnerRef.Id),
                                }
                            }
                        }).Entities.FirstOrDefault();

                        targetReference = targetUser?.ToEntityReference();
                    }
                }
                else
                {
                    var sourceTeam = sourceService.Retrieve("team", sourceOwnerRef.Id, new ColumnSet("name"));
                    name = sourceTeam.GetAttributeValue <string>("name");

                    // Let's find the team based on id or name
                    var targetTeam = targetService.RetrieveMultiple(new QueryExpression("team")
                    {
                        Criteria = new FilterExpression(LogicalOperator.Or)
                        {
                            Conditions =
                            {
                                new ConditionExpression("name",   ConditionOperator.Equal, name),
                                new ConditionExpression("teamid", ConditionOperator.Equal, sourceTeam.Id),
                            }
                        }
                    }).Entities.FirstOrDefault();

                    targetReference = targetTeam?.ToEntityReference();
                }

                if (targetReference != null)
                {
                    record["ownerid"] = targetReference;
                }
                else
                {
                    throw new Exception(string.Format(
                                            "Unable to find a user or team in the target organization with name '{0}' or id '{1}'",
                                            name,
                                            record.GetAttributeValue <EntityReference>("ownerid").Id));
                }
            }
        }