locked
How to limit the number of child entities (occurencies) / limit hierarchy members count RRS feed

  • Question

  • Hi,

    For my company model, I have such requirements:

    example:

    Entity B with Domain Based Attribute : Entity A

    I need to limit the number of occurencies of Entity B

    For each entity "A" member, I would like to limit the number of entities "B" beetwen 0 and 8.

    I tried this solution:

    • a business rule to Generate the Code from 1 with a step of 1

    AND

    • a business rule : CODE must be beetween 1 and 8

    BUT:

    If I delete an existing member : e.g: member with CODE = 5, when I create a new member, it won't take the CODE 5 that was deleted, but it will go on incrementing the values

    e.g. if a have 8 members with CODE from 1 to 8, and that I delete one of them, when I 'll try to create a new member, I would like it replace the deleted member, but currently MDS set the CODE to "9".

    Has anybody tried to implement a working solution  in order to limit the occurencies of a CHILD (Domain based Attribute) entity ?

    Thank you,

     

     



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

    Thursday, April 28, 2011 2:59 PM

Answers

  • Hi Xavier,

    One solution would be to kick off a SharePoint workflow on each time that a member is added.

    Within the workflow, you could use Web Service calls to determine the number of times that an entity is used. This will be much easier with .net rather than trying to use the MDS business rules, if it's even possible.

    You could use the web service calls to mark the member as invalid if an entity has been used more than 8 times. The obvious downside to this is that it still allows the 9th member to be created. The member will be marked as invalid, so any subscribing systems wouldn't pick it up if you filter on the validation status. It's obviously a fair bit of work to set up the workflow and write the .net code, but I can't see how it can be done with the standard business rules.

    Hope that helps

    Jeremy


    http://blogs.adatis.co.uk/blogs/jeremykashel/default.aspx
    Monday, May 2, 2011 7:25 PM
  • Hi Jeremy,

    I've implemented a custom workflow. Here is the C# code. It is working well, but one of our project requirement is to not develop custom code.

     

    public class OccurenciesCheck : IWorkflowTypeExtender
     {
      public void StartWorkflow(string workflowType, System.Xml.XmlElement dataElement)
      {
       Console.WriteLine(" workflow type: {0} ", workflowType);
       MDS_WSConnect.GetMappedExeConfigurationSections(Application.ExecutablePath+".config");
       CheckOccurencies(dataElement);
       XmlTextWriter writer = new XmlTextWriter(Console.Out);
       writer.Formatting = Formatting.Indented;
       dataElement.WriteTo(writer);
    
      }
    
      private void CheckOccurencies(XmlElement dataElement)
      {
       string modelName = dataElement["Model_Name"].InnerText;
       string entityName = dataElement["Entity_Name"].InnerText;
       string enterVersionName = dataElement.GetElementsByTagName("EnterVersionName")[0].InnerText;
       using (var client = MDS_WSConnect.CreateMdsProxy())
       {
    
        EntityMembersGetRequest request = new EntityMembersGetRequest();
        request.MembersGetCriteria = new EntityMembersGetCriteria();
        request.MembersGetCriteria.ModelId = new Identifier() { Name = modelName };
        request.MembersGetCriteria.VersionId = new Identifier() { Name = enterVersionName };
        request.MembersGetCriteria.EntityId = new Identifier() { Name = entityName };
        request.MembersGetCriteria.MemberReturnOption = MemberReturnOption.Counts;
        EntityMembersInformation emi = new EntityMembersInformation();
        OperationResult or = new OperationResult();
        //submit the request to the MDS Web Service Client
        client.EntityMembersGet(new International(), request.MembersGetCriteria, out emi, out or);
        if (emi.TotalMemberCount > 8)
        {
         MessageBox.Show("You can only have 8 members for that entity");
         //TODO unvalidate record
        }
       }
    
    
      }
     }
    

     For those who are interested, here is how to implement a custom MDS workflow:

    http://cicoria.com/cs1/blogs/cedarlogic/archive/2010/11/14/extending-sql-2008-r2-master-data-services-mds-with-iworkflowtypeextender.aspx

     

    So we thought about a different solution.

    We will use a specific attribute as a member counter (number format), that users will manually edit and add a business rule ": this attribute must be between 0 and 8)

    Thank you,

     



    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, May 4, 2011 8:20 AM
  • Hi all,

    another solution without custom workflow

    (many thanks to Marius Z. for his help)

    1)      Add a number attribute called “Multiplicity”on the entity you wish to limit the member count

    2)      OPTIONAL : add a business rule (1) “CODE GENERATED” : CODE is generated from 1 step 1 (this rule avoids the user to enter a manual code)

    3)      Add a business rule (2) called “Occurrences Limit” : Multiplicity must be between 1 and 8 (1 and 8 by example)

    4)      Add a business rule (3) called “unique occurrence” : multiplicity must be unique relatively to its parent entity

    5)      OPTIONAL : add a business rule (4) “CONCATENATED CODE”: CODE EQUALS A CONCATENATED VALUE : DBA.parentAttribute + “_” + Multiplicity where DBA.parentAttribute is the parent DBA attribute (this rule to make the code more “readable” for the mds operator/mds user)

    Note: You can also group rule (2) and (3)

    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".
    Monday, May 9, 2011 2:35 PM

All replies

  • Hi,

    Maybe that I could use explicit hierarchies and use N consolidated members (and then Restrict access for users in order to not be able to add more consolidated members)

      I want to limit the members count to N members, but I would not prefer to use this solution as explicit hierarchies would make my model more complex and even I 'm not sure it could work like this.

    Do someone have any solution ?

    thank you.



    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".


    Monday, May 2, 2011 3:31 PM
  • Hi Xavier,

    One solution would be to kick off a SharePoint workflow on each time that a member is added.

    Within the workflow, you could use Web Service calls to determine the number of times that an entity is used. This will be much easier with .net rather than trying to use the MDS business rules, if it's even possible.

    You could use the web service calls to mark the member as invalid if an entity has been used more than 8 times. The obvious downside to this is that it still allows the 9th member to be created. The member will be marked as invalid, so any subscribing systems wouldn't pick it up if you filter on the validation status. It's obviously a fair bit of work to set up the workflow and write the .net code, but I can't see how it can be done with the standard business rules.

    Hope that helps

    Jeremy


    http://blogs.adatis.co.uk/blogs/jeremykashel/default.aspx
    Monday, May 2, 2011 7:25 PM
  • Hi Jeremy,

    thank you for your good idea.

    Our company MDS model contains a huge quantity of entities.

    I'll try to make my custom .NET code as generic as possible, as limit to "8 times" was just an example, and we've got a lot a specific members count limitation to manage.

    I'll keep you informed about that point.

     



    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".
    Tuesday, May 3, 2011 9:03 AM
  • Hi Jeremy,

    I've implemented a custom workflow. Here is the C# code. It is working well, but one of our project requirement is to not develop custom code.

     

    public class OccurenciesCheck : IWorkflowTypeExtender
     {
      public void StartWorkflow(string workflowType, System.Xml.XmlElement dataElement)
      {
       Console.WriteLine(" workflow type: {0} ", workflowType);
       MDS_WSConnect.GetMappedExeConfigurationSections(Application.ExecutablePath+".config");
       CheckOccurencies(dataElement);
       XmlTextWriter writer = new XmlTextWriter(Console.Out);
       writer.Formatting = Formatting.Indented;
       dataElement.WriteTo(writer);
    
      }
    
      private void CheckOccurencies(XmlElement dataElement)
      {
       string modelName = dataElement["Model_Name"].InnerText;
       string entityName = dataElement["Entity_Name"].InnerText;
       string enterVersionName = dataElement.GetElementsByTagName("EnterVersionName")[0].InnerText;
       using (var client = MDS_WSConnect.CreateMdsProxy())
       {
    
        EntityMembersGetRequest request = new EntityMembersGetRequest();
        request.MembersGetCriteria = new EntityMembersGetCriteria();
        request.MembersGetCriteria.ModelId = new Identifier() { Name = modelName };
        request.MembersGetCriteria.VersionId = new Identifier() { Name = enterVersionName };
        request.MembersGetCriteria.EntityId = new Identifier() { Name = entityName };
        request.MembersGetCriteria.MemberReturnOption = MemberReturnOption.Counts;
        EntityMembersInformation emi = new EntityMembersInformation();
        OperationResult or = new OperationResult();
        //submit the request to the MDS Web Service Client
        client.EntityMembersGet(new International(), request.MembersGetCriteria, out emi, out or);
        if (emi.TotalMemberCount > 8)
        {
         MessageBox.Show("You can only have 8 members for that entity");
         //TODO unvalidate record
        }
       }
    
    
      }
     }
    

     For those who are interested, here is how to implement a custom MDS workflow:

    http://cicoria.com/cs1/blogs/cedarlogic/archive/2010/11/14/extending-sql-2008-r2-master-data-services-mds-with-iworkflowtypeextender.aspx

     

    So we thought about a different solution.

    We will use a specific attribute as a member counter (number format), that users will manually edit and add a business rule ": this attribute must be between 0 and 8)

    Thank you,

     



    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, May 4, 2011 8:20 AM
  • Hi all,

    another solution without custom workflow

    (many thanks to Marius Z. for his help)

    1)      Add a number attribute called “Multiplicity”on the entity you wish to limit the member count

    2)      OPTIONAL : add a business rule (1) “CODE GENERATED” : CODE is generated from 1 step 1 (this rule avoids the user to enter a manual code)

    3)      Add a business rule (2) called “Occurrences Limit” : Multiplicity must be between 1 and 8 (1 and 8 by example)

    4)      Add a business rule (3) called “unique occurrence” : multiplicity must be unique relatively to its parent entity

    5)      OPTIONAL : add a business rule (4) “CONCATENATED CODE”: CODE EQUALS A CONCATENATED VALUE : DBA.parentAttribute + “_” + Multiplicity where DBA.parentAttribute is the parent DBA attribute (this rule to make the code more “readable” for the mds operator/mds user)

    Note: You can also group rule (2) and (3)

    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".
    Monday, May 9, 2011 2:35 PM
  • Xavier,

    I find a similar problem. I can define the unique rule, yet I get an error when I attempt to publish it.

    I cannot seem to publish any unique rule where I am applying it to a domain based attribute. 

    Can you provide any insight?

    

    Tuesday, June 19, 2012 9:26 AM