locked
Create an attribute group by api RRS feed

  • Question

  • Hi all,

    can somebody provide a code sample how to create an attribute group by api webservice.

    thanks a lot !

    Marco

    Sunday, July 17, 2011 7:57 AM

Answers

  • Hi Marco

    did you try something like this ? (not tested yet)

     

     

     private OperationResult CreateAttributeGroup(Identifier modelId, Entity entityId)
     {
      OperationResult or = null;
      Common.MDS_WS mds = new MDS_WS();
    
      Metadata md = new Metadata();
      if (entityId != null)
      {
      or = new OperationResult();
    
    
      md.AttributeGroups = new Collection<AttributeGroup>();
      md.AttributeGroups.Add(new AttributeGroup()
      {
       Attributes = new Collection<MetadataAttribute>(),
       FullName = "TestAttributeGroup",
       IsNameCodeFrozen = false,
       Identifier = new MemberTypeContextIdentifier() { EntityId = entityId.Identifier, MemberType = MemberType.Leaf, ModelId = modelId },
       IsSystem = false
      });
    
    
      using (ServiceClient c = MDS_WSConnect.CreateMdsProxy())
      {
       c.MetadataCreate(new International(), md, true, out or);
       
      }
      }
      
      return or;
     
     }
    

     

    you will need to complete the collection of MetadataAttribute>() at first, in order to make this work,

    by the way, if you need some more example, you can download my free MDS tool with source code here:

    http://mdsmanager.codeplex.com

    Regards,



    Xavier Averbouch
    Microsoft Community Contributor
    Avanade , FRANCE
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful".

    • Marked as answer by M_A_M Wednesday, May 2, 2012 7:14 AM
    Thursday, July 21, 2011 9:13 AM

All replies

  • Hi Marco

    did you try something like this ? (not tested yet)

     

     

     private OperationResult CreateAttributeGroup(Identifier modelId, Entity entityId)
     {
      OperationResult or = null;
      Common.MDS_WS mds = new MDS_WS();
    
      Metadata md = new Metadata();
      if (entityId != null)
      {
      or = new OperationResult();
    
    
      md.AttributeGroups = new Collection<AttributeGroup>();
      md.AttributeGroups.Add(new AttributeGroup()
      {
       Attributes = new Collection<MetadataAttribute>(),
       FullName = "TestAttributeGroup",
       IsNameCodeFrozen = false,
       Identifier = new MemberTypeContextIdentifier() { EntityId = entityId.Identifier, MemberType = MemberType.Leaf, ModelId = modelId },
       IsSystem = false
      });
    
    
      using (ServiceClient c = MDS_WSConnect.CreateMdsProxy())
      {
       c.MetadataCreate(new International(), md, true, out or);
       
      }
      }
      
      return or;
     
     }
    

     

    you will need to complete the collection of MetadataAttribute>() at first, in order to make this work,

    by the way, if you need some more example, you can download my free MDS tool with source code here:

    http://mdsmanager.codeplex.com

    Regards,



    Xavier Averbouch
    Microsoft Community Contributor
    Avanade , FRANCE
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful".

    • Marked as answer by M_A_M Wednesday, May 2, 2012 7:14 AM
    Thursday, July 21, 2011 9:13 AM
  • Xavier,

    I realize this post has been closed for quite some time but I needed to do the same thing and I can't seem to get the code to work.  Here is what I have:

               

                public MDS.OperationResult AddAttributeGroup(MDS.Identifier modelId, MDS.Identifier entityId, string attributeGroupName, string[] attNames)
                {
                    MDS.OperationResult or = null;
                    MDS.Metadata md = new MDS.Metadata();
    
                    if (entityId != null)
                    {
                        or = new MDS.OperationResult();
    
                        List<MDS.AttributeGroup> ls = new List<MDS.AttributeGroup>();
                        MDS.AttributeGroup attGrp = new MDS.AttributeGroup();
    
                        attGrp.Identifier = new MDS.MemberTypeContextIdentifier() { EntityId = entityId, MemberType = MDS.MemberType.Leaf, ModelId = modelId };
                        attGrp.FullName = attributeGroupName;
                        attGrp.IsNameCodeFrozen = false;
                        attGrp.IsSystem = false;
    
                        List<MDS.MetadataAttribute> ls2 = new List<MDS.MetadataAttribute>();
    
                        foreach (string attName in attNames)
                        {
                            ls2.Add(new MDS.MetadataAttribute()
                            {
                                Identifier = new MDS.MemberTypeContextIdentifier()
                                {
                                    EntityId = entityId,
                                    ModelId = modelId,
                                    MemberType = MDS.MemberType.Leaf,
                                    Name = attName
                                }
                            });
                        }
    
                        attGrp.Attributes = ls2.ToArray();
    
                        md.AttributeGroups = ls.ToArray();
    
                        MDS.ServiceClient proxy = CreateMdsProxy();
                        proxy.MetadataCreate(International, md, true, out or);
                    }
    
                    return or;
    
                }

    I am trying to add a list of existing attributes into the attribute group but nothing seems to be happening. No errors are getting returned in the OperationalResult and the attribute group is not getting created. Any thoughts?

    Thank you,

    Don

    Wednesday, December 12, 2012 8:00 PM
  • Hi Don

    unfortunately, I dont' work any more on MDS for more than 1 year

    I don't even have a working MDS installation for testing

    BUT... you could find what you need in my old codeplex project : http://mdsmanager.codeplex.com/

    Till version 1.05 the source code is available : http://mdsmanager.codeplex.com/SourceControl/changeset/view/16392#

    and maybe it could be usefull to understand where your issue is.

    Regards,

    Xavier



    Xavier Averbouch
    Microsoft Community Contributor
    Avanade , FRANCE
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful".

    Wednesday, December 12, 2012 9:48 PM