简体   繁体   English

无法在 Dynamics CRM 365 online 中创建系统用户

[英]Unable to Create a systemuser in Dynamics CRM 365 online

On update field of contact record I want to create a systemuser(user) in dynamics crm 365 online.but I'm getting error like "usersettings With Id = 5fe33120-607f-e811-a95c-000d3af29269 Does Not Exist"在联系人记录的更新字段上,我想在动态 crm 365 在线创建一个系统用户(用户)。

This is the below code I'm trying to create a user这是我正在尝试创建用户的以下代码

Entity getEntity = (Entity)context.InputParameters["Target"];
                string str = getEntity.Attributes["new_isaeon"].ToString();

                if (str != null && str == "True")
                {
                    // http://localhost:51625/api/Users
                    Entity sysuser = new Entity("systemuser");
                    sysuser.Attributes["fullname"] = "hsk";
                    sysuser.Attributes["internalemailaddress"] = "projectservice_9@crmdemo.dynamics.com";
                    sysuser.Attributes["domainname"] = "projectservice_9@crmdemo.dynamics.com";
                    Guid getGuid = new Guid("700F2217-786A-E811-A95A-000D3AF2793E");
                    sysuser.Attributes["businessunitid"] = new EntityReference("businessunit", getGuid);
                    sysuser.FormattedValues["accessmode"] = "Read-Write";
                    Guid getuserid = service.Create(sysuser);

                }

can anyone help me on this thanks.任何人都可以帮助我,谢谢。

Update : Recently we started importing users in CRM online directly using OOB CSV import (this is new for me too), it will succeed, and later on when license assigned for same user - this wont create another user record, instead it will map the Azure object GUID to the existing user record based on username/domain name/email.更新:最近我们开始使用 OOB CSV 导入直接在线 CRM 中导入用户(这对我来说也是新的),它会成功,稍后当为同一用户分配许可证时 - 这不会创建另一个用户记录,而是将映射基于用户名/域名/电子邮件的现有用户记录的 Azure 对象 GUID。 This is more useful when creating stub users without license or roles quickly.这在快速创建没有许可证或角色的存根用户时更有用。


In Dynamics 365 CRM online, system users record creation/enabling flow happens from O365 Admin portal end.在 Dynamics 365 CRM online 中,系统用户记录创建/启用流程发生在 O365 管理门户端。 Read more 阅读更多

Steps go like this:步骤如下:

  1. Security group has to be created in Active directory & mapped in O365 Admin portal for any CRM Org必须在 Active Directory 中创建安全组并映射到任何 CRM 组织的 O365 管理门户
  2. Users has to be added in that AD Security group必须在该 AD 安全组中添加用户
  3. All the users from SG will be replicated as system users in CRM instance SG 的所有用户将被复制为 CRM 实例中的系统用户
  4. In O365 Admin portal, on assigning CRM license (Basic/Pro) against the user - the system user record will be enabled in CRM在 O365 管理门户中,针对用户分配 CRM 许可证(基本版/专业版)时 - 将在 CRM 中启用系统用户记录
  5. In CRM side, we will assign Security role to complete user on-boarding在 CRM 端,我们将分配安全角色来完成用户入职

We cannot create system user using SDK directly because of above manual steps outside CRM online.由于上述 CRM 在线之外的手动步骤,我们无法直接使用 SDK 创建系统用户。 Can be created using PowerShell like answered in community .可以使用 PowerShell 创建,就像在社区中回答的一样。

//Use below code to create User in D365 //使用下面的代码在D365中创建用户

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

namespace PowerApps.Samples
{
    public partial class SampleProgram
    {
        static void Main(string[] args)
        {
            JObject azureUser = new JObject();
            JObject retrievedResult;
            string queryOptions = string.Empty;
            string domainName = string.Empty;
            try
            {
                Console.WriteLine("Please enter domain name.");
                domainName = Console.ReadLine();

                string connectionString = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;

                using (HttpClient client = SampleHelpers.GetHttpClient(
                    connectionString,
                    SampleHelpers.clientId,
                    SampleHelpers.redirectUrl,
                    "v9.1"))
                {

                    queryOptions = "systemusers?$select=domainname&$filter=domainname eq '" + domainName + "'";

                    HttpResponseMessage retrieveResponse = client.GetAsync(client.BaseAddress.AbsoluteUri + queryOptions,
                        HttpCompletionOption.ResponseHeadersRead).Result;

                    if (retrieveResponse.IsSuccessStatusCode) //200
                    {
                        retrievedResult = JObject.Parse(retrieveResponse.Content.ReadAsStringAsync().Result);
                        string outputDomainname = (string)retrievedResult.SelectToken("value[0].domainname");
                        Console.WriteLine("Domain: " + outputDomainname);
                        if (outputDomainname == null)
                        {
                            Console.WriteLine("Adding user to Azure AD..");

                            HttpRequestMessage createrequest = new HttpRequestMessage(HttpMethod.Post,
                                client.BaseAddress + "systemusers");

                            Console.WriteLine("Enter first name");
                            azureUser.Add("firstname", Console.ReadLine());

                            Console.WriteLine("Enter last name");
                            azureUser.Add("lastname", Console.ReadLine());

                            Console.WriteLine("Enter internal email address");
                            azureUser.Add("internalemailaddress", Console.ReadLine());

                            azureUser.Add("isdisabled", false);
                  
                            azureUser.Add("caltype", 7);
                            azureUser.Add("businessunitid@odata.bind", "/businessunits(8c44c8ac-f6a3-ea11-a812-000d3a0a74cb)");

                            createrequest.Content = new StringContent(azureUser.ToString());
                            createrequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                            HttpResponseMessage createResponse = client.SendAsync(createrequest, HttpCompletionOption.ResponseHeadersRead).Result;
                            if (createResponse.IsSuccessStatusCode)
                            {
                                Console.WriteLine("Account created");
                            }
                            else
                            {
                                throw new Exception(string.Format("Failed to Post Records", createResponse.ReasonPhrase));
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Failed to retrieve domain: {0}",
                            retrieveResponse.ReasonPhrase);
                        throw new Exception(string.Format("Failed to retrieve domain: {0}", retrieveResponse.Content));
                    }
                }
            }
            catch (Exception ex)
            {
                SampleHelpers.DisplayException(ex);
                throw ex;
            }
            finally
            {
                Console.WriteLine("Press <Enter> to exit the program.");

                Console.ReadLine();
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM