Object Script equivalent to Studio "Find in Files"

Primary tabs

I've been trying to figure out how to use an ObjectScript class to search other classes for specific strings.  To be very specific, I want to be able to search business rules to see if a particular DTL is in the rule.  We have some orphaned DTL's in our Ensemble productions and I want to make sure that they're not being used.

 

Thanks.

  • 0
  • 0
  • 108
  • 3
  • 2

Answers

You might be interested in the new Interface Maps feature launched in 2019.1. It, among other things, allows you to search for any business rules that refer to a chosen DTL.

https://docs.intersystems.com/healthconnect20191/csp/docbook/Doc.View.cl...

Thank you, I'll keep that in mind.  That said, I still need the code solution because we won't be upgrading for several months.

Business rule classes store the rules as XML in an XData block with the name "RuleDefinition":

Class Demo.Rule.GenericRouter Extends Ens.Rule.Definition
{

Parameter RuleAssistClass = "EnsLib.MsgRouter.RuleAssist";

XData RuleDefinition [ XMLNamespace = "http://www.intersystems.com/rule" ]
{
<ruleDefinition alias="" context="EnsLib.MsgRouter.RoutingEngine" production="TESTINGPKG.FoundationProduction">
<ruleSet name="" effectiveBegin="" effectiveEnd="">
<rule name="">
<when condition="1">
<send transform="Demo.DTL.Generic" target="Test.DummyOperation"></send>
<return></return>
</when>
</rule>
</ruleSet>
</ruleDefinition>
}

}

One approach would be to find all of your business rule classes, retrieve the "RuleDefinition" XData block for each one, and then parse the XML to see which DTLs are called.

To find the business rule classes, have a look at %Dictionary.ClassDefinition. You could do a query like this to find your business rule classes:

select ID from %Dictionary.ClassDefinition where super='Ens.Rule.Definition'

Then, for each business rule class you can find the %Dictionary.XDataDefinition for the RuleDefinition XData block with a query like this:

select ID from %Dictionary.XDataDefinition where parent='Demo.Rule.GenericRouter' and name='RuleDefinition'

The raw XML from the XData block can be accessed via the stream object stored in the "Data" property of the %Dictionary.XDataDefinition row.

So far, it makes perfect sense.  The part I can't figure out is how to define the variable and actually get to the information.

Check for the following methods:

FindInFiles and FindInFilesRegex.

Optionally you could limit the search for a single project using the method FindInProject.

All methods belong to the %Studio.Project class.

Here's how Atelier does:

            Set tSC=##class(%Studio.Project).FindInFiles(
                tSearch,
                doclist,
                system,
                wholeword,
                casesensitive,
                max,
                "GENERATED="_generated, // filter
                wildcards
            )

But you'll need to use device redirection to capture and parse its content. Because Studio uses these methods to display the results in the Output window.