Sample scenario: Create a new group

Today we are going to create a new group using web services.  To create a new group, like creating any object in ILM, you must provide a starting value that includes all of the required attributes.  In the case of a group, we need to set a few more attributes than we would with other objects because groups are so important to the system.  Our example below includes the necessary attributes for a group.  To see which attributes are required for ILM objects, re-visit the previous post about getting ILM schema and look at the required attribute bindings or explore the schema in the ILM portal. I will leave both as an exercise to the reader since doing is the best way to learn.

(Hint: Output binding[“Required”].AttributeSingleValue.ToString().  If true, you must include the attribute).

The code to create a group:

static void Topic15CreateGroup()

        {

            WSTransferClient transferClient = new WSTransferClient();

            transferClient.ClientCredentials = GetCredentials();

 

            ResourceManagementObject rmObject = new ResourceManagementObject("Group");

            rmObject["DisplayName"] = new ResourceManagementAttribute("DisplayName", "CreatedGroupDisplay");

            rmObject["Scope"] = new ResourceManagementAttribute("Scope", "Universal");

            rmObject["AccountName"] = new ResourceManagementAttribute("AccountName", "CreatedGroup");

            rmObject["Domain"] = new ResourceManagementAttribute("Domain", Domain);

            rmObject["MembershipAddWorkflow"] = new ResourceManagementAttribute("MembershipAddWorkflow", "None");

            rmObject["Owner"] = new ResourceManagementAttribute(true, "Owner");

            rmObject["Owner"].AddMultiValue(GetPersonId);

            rmObject["MembershipLocked"] = new ResourceManagementAttribute("MembershipLocked", "False");

            rmObject["Type"] = new ResourceManagementAttribute("Type", "Distribution");

 

            rmObject["MailNickname"] = new ResourceManagementAttribute("MailNickname", "CreatedGroupMailName");

            rmObject["DisplayedOwner"] = new ResourceManagementAttribute("DisplayedOwner", GetPersonId);

 

            String newGroupId = transferClient.Create(rmObject);

            Assert.IsNotNull(newGroupId);

 

            ResourceManagementObject retrievedGroup = transferClient.Get(newGroupId);

            Assert.IsNotNull(retrievedGroup);

            Assert.IsTrue(newGroupId.Equals(retrievedGroup.ObjectId));

 

            Console.WriteLine("Topic 15 Complete");

        }

I hope you agree that this code is straight-forward.  We create a new object, set a bunch of required attributes, and then pass the object to create.  We then get back the object’s ID in the create response, which we then can use for getting the object or searching for it in enumerations.

The only tricky part to creating an object is, as I originally mentioned, to ensure all required attributes are present and that they are in the correct format.  Please explore creating new objects including any custom objects you may have added.  If things keep failing, turn on WCF message tracing and watch how the portal does it.

I uploaded the sample create request on the code gallery site so you can compare what an ILM “2” RC request should look like.  Happy exploring!