21-04-2016 05:19 PM
I am running a modeling rule using the follwoing code:
oRule = getRoot().getObjectFromID("~bIGR5)c0NrZQ['On Premises' type Applications should have recommended assocations]") oToBeRuled = getRoot().getObjectFromID("~IUnzipl2MzJ)[VSP]") print oRule.getProp("Short Name") print oToBeRuled.GetProp("Short Name") sResult = "" sResult = oRule.RuleApply(oToBeRuled) print sResult
This works fine however i am not able to figure out how to get the error report when a modeling rule fails. The modeling rule macro was setup as follows:
Option Explicit Sub RuleAppliableIs (oToBeRuled, oRule, sParameter, bRuleAppliableIs) bRuleAppliableIs = false if oToBeRuled.getProp("Cloud Computing") = "1OP" then bRuleAppliableIs = true End if end sub Sub RuleWithReportApply (oToBeRuled, oRule, sParameters, bRuleResult, sErrorReport) bRuleResult = false if oToBeRuled.GetCollection("Server").count > 0 And oToBeRuled.GetCollection("Site").count > 0 And oToBeRuled.GetCollection("Used Technology").count > 0 And oToBeRuled.GetCollection("Required Technical Infrastructure").count > 0 then bRuleResult = true else sErrorReport = "Missing one or all of following associations : Server,Site,Used Technology,Required Technical Infrastructure" End if end sub
When you right click on an object and you run check --> regulation with propgation it prints out sErrorReport.
I tried to find this report to see how it was implemented but it seems that is is part of a dll somewhere. So is there anyway to get this informaiton about a fialed modeling rule from the API?
Solved! Go to Solution.
02-05-2016 03:52 PM - edited 02-05-2016 04:58 PM
Thank you. This seems to work. Now that I have a working example in VB i think i can implement this in Java. I do have one more quesiton. Not all modeling rules use RuleWithReportApply some just use RuleApply and others don't implement Macro's they use MetaTest. Is there a way to test to make sute the RuleWithReportApply method has been implemented?
28-04-2016 02:45 PM
Hello,
I think you need to call the macro :
oRule = getRoot().getObjectFromID("~bIGR5)c0NrZQ['On Premises' type Applications should have recommended assocations]") oToBeRuled = getRoot().getObjectFromID("~IUnzipl2MzJ)[VSP]") Set myMacro = CurrentEnvironment.getMacro(oRule.getCollection("~d)mXIQv51vy0[Macro d'implementation]").item(1).shortname) Call myMacro.RuleWithReportApply(oToBeRuled, oRule, sParameters, bRuleResult, sErrorReport) print oRule.getProp("Short Name") print oToBeRuled.GetProp("Short Name") print bRuleResult print sErrorReport
Regards,
Lionel
25-04-2016 06:03 PM
The regulation report is able to show this information. Is there any other way to get this information ?
21-04-2016 07:22 PM
Thanks for responding but I tried that and it dosen't work. It will only print the attribute value as you can see below:
What I'm trying to get is from the implementing macro that is connected to the modeling rule
This shows up in the regulation report
21-04-2016 06:14 PM
Hello FM_MEGA
If I understand, you want to apply a modeling rule using API script and get the text result in case of success or failure
You can use this to get the text result in case of failure
oRule.GetProp("~vxKaP7Pu0z80[When rule is not valid] ","Display")
Script example (VB script)
Set oApp = GetObjectFromId("~X2n9DT2rMzMN[A01]") Set oRule = GetObjectFromID("~o6OrCgnB2fp2[An application cannot be a component of itself]") ' to get a boolea result Print oRule.RuleApply(oApp) ' to get a text if rule applies successfully Print oRule.GetProp("~Sts8Kcqg1D80[Rule Description]","Display") ' to get a text if rule application fails Print oRule.GetProp("~vxKaP7Pu0z80[When rule is not valid] ","Display")