Question
· Jan 8, 2020

Object Script equivalent to Studio "Find in Files"

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.

Discussion (6)1
Log in or sign up to continue

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.

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.