Insert Data into MDS Entity from User Input programatically (MDS API)

Category: sql server masterdata

Question

JahanzebKhan321 on Wed, 15 Jun 2016 13:06:30


I am trying to create entity member with the "EntityMemberCreate" function but it only create a record with Member name and the attributes columns remain empty. Can anyone tell me how to insert data in entity along with member name. I am passing user's input to this function as parametes.  Here is the code I am using:

private static void CreateEntityMember(string modelName, string versionName, string entityName, string aNewMemberName, string aNewCode, MemberType memberType, string HierarchyName, string PersonName, string FatherName)
        {
            // Create the request object for entity creation.
            EntityMembersCreateRequest createRequest = new EntityMembersCreateRequest();
            createRequest.Members = new EntityMembers();
            createRequest.ReturnCreatedIdentifiers = true;
            // Set the modelId, versionId, and entityId.
            createRequest.Members.ModelId = new Identifier { Name = modelName };
            createRequest.Members.VersionId = new Identifier { Name = versionName };
            createRequest.Members.EntityId = new Identifier { Name = entityName };
            createRequest.Members.MemberType = memberType;
            createRequest.Members.Members = new System.Collections.ObjectModel.Collection<Member> { };
            Member aNewMember = new Member();
            aNewMember.MemberId = new MemberIdentifier() { Name = aNewMemberName, Code = aNewCode, MemberType = memberType };
            createRequest.Members.Members.Add(aNewMember);
            // Create a new entity member
            EntityMembersCreateResponse createResponse = clientProxy.EntityMembersCreate(createRequest);

            HandleOperationErrors(createResponse.OperationResult);

        }

It will create a member in database with NULL attributes i.e: PersonName, FatherName as they were not set in the Member setting option.

Can anybody tell me how to create members with these NULL attributes filled.


Replies

davidbaxterbrowne on Wed, 15 Jun 2016 13:15:13


Check out this project for a helper class and code samples.

http://mdsutilities.codeplex.com/

In particular: MDSEntityCRUDOperations.cs

David

JahanzebKhan321 on Thu, 16 Jun 2016 11:14:23


I have already checked that before but couldn't find a solution to this problem. Can you explain a bit.

davidbaxterbrowne on Thu, 16 Jun 2016 13:17:53


You're not setting the other attributes.  Should be something like

aNewMember.Attributes.Add( new MdsWebService.Attribute() { Identifier = new Identifier() { Name = "PersonName"},Type = AttributeDataType.Text, Value = PersonName});

. . .

David


David http://blogs.msdn.com/b/dbrowne/


JahanzebKhan321 on Fri, 17 Jun 2016 09:37:58


Really appreciate your help. After modification I was able to do perform this operation.