locked
Issue with Azure AD schema extension RRS feed

  • Question

  • I createe extension :

    SchemaExtension objExtDef = new SchemaExtension()
                {
                    Description = "Extention to Store User Dates",
                    Id = "UserDates",
                    Properties = new List<ExtensionSchemaProperty>()
                    {
                        new ExtensionSchemaProperty() { Name = "CreateDate", Type = "DateTime" },
                        new ExtensionSchemaProperty() { Name = "PasswordChangeDate", Type = "DateTime" }
                    },
                    TargetTypes = new List<string>()
                    {
                        "User"
                    }
                };


                SchemaExtension schemaExtension = Task.Run(() => graphserviceClient.SchemaExtensions.Request().AddAsync(objExtDef)).Result;

    Made it Available :

     var schemaExtension = new SchemaExtension
                {
                    Status = "Available",
                };

                var result = Task.Run(() => graphserviceClient.SchemaExtensions["extuce7u7qp_UserDates"].Request().UpdateAsync(schemaExtension)).Result;

    Searched and confirmed that it is created and available :

    var lstAllExtensions = Task.Run(() => graphserviceClient.SchemaExtensions.Request().Filter("id%20eq%20'extuce7u7qp_UserDates'").GetAsync()).Result;

    Trying to add user along with additional data in that extension :

     Microsoft.Graph.User objNewUser = new Microsoft.Graph.User
                        {
                            AccountEnabled = true,
                            DisplayName = string.Format("{0} {1}", objUser.FirstName, objUser.LastName),
                            MailNickname = "TestUC",
                            PasswordProfile = new PasswordProfile
                            {
                                Password = "testpass",
                                ForceChangePasswordNextSignIn = false
                            },
                            UserPrincipalName = string.Format("{0}@test.onmicrosoft.com", objUser.UserIdentity),
                            GivenName = objUser.FirstName,
                            Surname = objUser.LastName,
                            City = objUser.Address != null ? objUser.Address.City : null,
                            Country = objUser.Address != null ? objUser.Address.Country : null,
                            State = objUser.Address != null ? objUser.Address.Region : null,
                            MobilePhone = !string.IsNullOrEmpty(objUser.Phone) ? objUser.Phone : null,
                            PreferredLanguage = objUser.PreferredLanguage,
                            AdditionalData = dctExtensions


                        };

    Microsoft.Graph.User objCreatedUser = Task.Run(() => graphserviceClient.Users.Request().AddAsync(
                            objNewUser
                        )).Result;

    That is throwing exception that the extension ID is not valid. 

    This was working earlier.



    • Edited by Ram Choppa Monday, July 16, 2018 2:05 PM
    Thursday, July 12, 2018 1:43 PM

All replies

  • Hi Ram,

    I am able to create the user successfully with few modifications in the code which you have provided here.  

    Why are you creating a new SchemaExtension object while assigning the status ?

    var schemaExtension = new SchemaExtension
                {
                    Status = "Available",
                };

    I have retrieved the SchemaExtension object from extensions list and set the Status property to "Available" as below :-

    SchemaExtension testSchema = new SchemaExtension();testSchema = lstAllExtensions.First<SchemaExtension>();testSchema.Status = "Available";

    Also, I have added code for dctExtensions like below -

    IDictionary<string, object> dctExtensions = new Dictionary<string, object>();dctExtensions.Add("ext8sj4y2pf_UserDates", objUserDatesExtension);

    Tuesday, July 24, 2018 5:50 AM
  • Just checking in if you have had a chance to see our previous response. If this answers your query, do click “Mark as Answer” and Up-Vote for the same. And, if you have any further query do let us know.
    Friday, July 27, 2018 12:18 AM