Failed to validate Business Rule created by MDS API in MDS 2012

I used MDSModelImport and created business rules for composite primary keys by MDS API.

When I first insert data from excel, I faced error "A database error has occurred".

After I tried to edit and re-save with no changes in mds web site, It worked. but It didn't work from API.

Let me know. Please.

Error Log

error number is 208: Code 208 invalid object name 'cteDuplicates669d2125e1dfca7671b321a20c997505'

Code for creating and publishing for composite primary keys:

private static void CreateAndPublishPrimaryBR(string modelName, string entityName, string[] columnNames)
        {
            try
            {
                // Set Model and Entity objects.
                Identifier modelId = new Identifier { Name = modelName };
                Identifier entityId = new Identifier { Name = entityName };

                // Create the request object. 
                BusinessRulesCreateRequest ruleCreateRequest = new BusinessRulesCreateRequest();
                ruleCreateRequest.ReturnCreatedIdentifiers = true;
                ruleCreateRequest.BusinessRuleSet = new BusinessRules();

                // Create a new business rule.
                BusinessRule newRule = new BusinessRule();
                ruleCreateRequest.BusinessRuleSet.BusinessRulesMember = new List<BusinessRule> { };
                ruleCreateRequest.BusinessRuleSet.BusinessRulesMember.Add(newRule);

                newRule.Identifier = new MemberTypeContextIdentifier
                {
                    Name = "pk",
                    ModelId = modelId,
                    EntityId = entityId,
                    MemberType = MemberType.Leaf
                };

                newRule.Priority = 20;

                BRAction ruleAction = new BRAction();
                newRule.BRActions = new List<BRAction>();
                newRule.BRActions.Add(ruleAction);
                ruleAction.Sequence = 1;

                // Set the action prefix argument for Name attribute.
                BRAttributeArgument actionPrefix = new BRAttributeArgument();
                ruleAction.PrefixArgument = actionPrefix;
                actionPrefix.PropertyName = BRPropertyName.Anchor;
                actionPrefix.AttributeId = new Identifier { Name = columnNames[0] };

                // Set the action operator.
                ruleAction.Operator = BRItemType.Unique;

                if (columnNames.Length > 1)
                {
                    // Set the action postfix argument for 
                    ruleAction.PostfixArguments = new List<object>();
                    for( int i= 1; i < columnNames.Length; i++)
                    {
                        BRAttributeArgument postArgument = new BRAttributeArgument();
                        ruleAction.PostfixArguments.Add(postArgument);
                        postArgument.PropertyName = BRPropertyName.Anchor;
                        postArgument.AttributeId = new Identifier { Name = columnNames[i] };
                    }
                }
                
                // Create the business rule.
                BusinessRulesCreateResponse ruleCreateResponse = mds.BusinessRulesCreate(ruleCreateRequest);

                HandleOperationErrors(ruleCreateResponse.OperationResult);

                // Create the request object.
                BusinessRulesPublishRequest rulePublishRequest = new BusinessRulesPublishRequest();
                rulePublishRequest.BRPublishCriteria = new BRPublishCriteria();
                rulePublishRequest.BRPublishCriteria.EntityId = entityId;
                rulePublishRequest.BRPublishCriteria.ModelId = modelId;
                rulePublishRequest.BRPublishCriteria.MemberType = BREntityMemberType.Leaf;

                // Publish the business rule.
                MessageResponse rulePublishResponse = mds.BusinessRulesPublish(rulePublishRequest);

                HandleOperationErrors(rulePublishResponse.OperationResult);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex);
            }
        }




September 2nd, 2015 11:45am

Hi Takatoshi,

Thank you for your question. 

I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 

Thank you for your understanding and support.

Regards,

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 9:20pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics