Freigeben über


Walkthrough: Update members in SQL Server Master Data Service using MDS API

Generally, we can use the EntityMembersUpdate method from MDS web services to update members in MDS. However, you may like to know how to update members, which have an attribute with a specific value.
This article walks through the steps about how to get expected members, and then update them.

Add a service reference to the MDS web service

The detailed steps are described in the following article, which is provided by the Master Data Services team.
Getting Started with the Web Services API in SQL Server 2008 R2 Master Data Services

Use the following to get expected members, and then update them
 

            EntityMembersGetRequest getRequest = new EntityMembersGetRequest();

            EntityMembersGetResponse getResponse = new EntityMembersGetResponse();

            //Represents a request complex type that defines the EntityMember criteria for the operations result set.

            EntityMembersGetCriteria memberGetCriteria = new EntityMembersGetCriteria();

            //Sets GUID or the exact name of the model.

            memberGetCriteria.ModelId = new Identifier() { Name = "Product"};

            //Sets a GUID or the exact name of the entity.

            memberGetCriteria.EntityId = new Identifier() { Name = "Product"};

            //Sets the GUID or the exact name of the version.

            memberGetCriteria.VersionId = new Identifier() { Name = "VERSION_1" };

            //Sets a WHERE clause search criteria to filter records. In this sample, we want to get members, which have the attribute 'TestAttribute' with value 'abc'

            memberGetCriteria.SearchTerm = String.Format(" [TestAttribute] = '{0}' ", "abc");

            getRequest.MembersGetCriteria = memberGetCriteria;

            getResponse = mdsProxy.EntityMembersGet(getRequest);

            Collection<Member> members = new Collection<Member>();

            if (getResponse.EntityMembers.Members.Count > 0)

            {

                foreach (Member individualMember in getResponse.EntityMembers.Members)

                {

                    //Update the value of the attribute 'TestAttribute', change it from 'abc' to 'cba'

                    individualMember.Attributes = new Collection<MDService.Attribute>() { new MDS.MDService.Attribute() { Identifier = new Identifier() { Name = "TestAttribute" }, Value = "cba" } };

                    //Add the member to the member collection.

                    members.Add(individualMember);

                }

            }

            // Create the request and response objects

            EntityMembersUpdateRequest request = new EntityMembersUpdateRequest();

            EntityMembersUpdateResponse response = new EntityMembersUpdateResponse();

            EntityMembers requestMember = new EntityMembers();

            requestMember.EntityId = new Identifier() { Name = "Product" };

            requestMember.ModelId = new Identifier() { Name = "Product" };

            requestMember.VersionId = new Identifier() { Name = "VERSION_1" };

            //Add the modified members to the members property.

            requestMember.Members = members;

            request.Members = requestMember;

            // Make the service request to update the members.

            response = mdsProxy.EntityMembersUpdate(request);

Set the SearchTerm property

The SearchTerm property is a string, which gets or sets a WHERE clause search criteria to filter records. Its format must be in this format:

[AttributeName] Operation value OperationParemter

AttributeName is the name of an attribute

· Operation can be in one of the following operations:
REGEX

· >

· >=

· IN

· =

· <>

· IS NOT NULL

· IS NULL

· <

· <=

· LIKE

· MATCH

· NOT REGEX

· NOT IN

· NOT LIKE

· NOT MATCH

Value is the criteria used for searching.

OperationParemter only be used when you use uncertain operation (e.g. Match).

Reference

IService.EntityMembersUpdate Method

IService.EntityMembersGet Method

Comments

  • Anonymous
    May 01, 2012
    Can we combine multiple Search Condition with SearchTerm for example like (A='abc' AND B='xyz') OR C='zxc'? Thanks, Utkarsh

  • Anonymous
    May 01, 2012
    @Utkarsh, Yes, we can. Please see the following sample: string searchterm = String.Format(" [Color]='{0}' AND [Shape] = '{1}'", "Red", "Square"); Alternatively, I would suggest you posting the question in social.msdn.microsoft.com/.../threads