Article
· Sep 26, 2016 2m read

Tips & Tricks - Export object to global

We're developing Ensemble PoC and one day our frontend developer (who doesn't have Ensemble production running) said that Populate just doesn't cut it and he needs to see the real data. He needed only one object, but the problem was - it's a big object. Still, I checked ids of everything related and wrote this command (parts omitted, but you get the idea):

w
$SYSTEM.OBJ.Export("project.model.contract.ContractD(6456).gbl,project.model.coA7F9.ObjectAddressD(6741).gbl,project.model.meter.DeviceD(23398).gbl,project.model.StatusHistoryD(7977).gbl,project.model.StatusHistoryD(48006).gbl,project.model.StatusHistoryD(83906).gbl","C:\Users\eduard\Desktop\export.xml")

Well, later it turns out that more than one object is needed, and I had most certainly not enjoyed traversing references manually, so I wrote the utility to export objects (underlying globals really) to XML. Check it out on GitHub. I won't post all the code, but here are some interesting snippets.

Snippets

Get data global for an active class storage strategy:

ClassMethod getDataGlobal(class As %String) As %String
{
    set strategy = $$$comClassKeyGet(class, $$$cCLASSstoragestrategy)
    return $$$defMemberKeyGet(class, $$$cCLASSstorage, strategy, $$$cSDEFdatalocation)
}

Get list of children/many objects ids for parentId (copied from %RelationshipObject:Load):

/// class - property type, property - INVERSE property name, parentId - id, for which we constrict list of id
ClassMethod getManyForOne(class As %String, property As %String, parentId As %Integer) As %List
{
    set sc=$classmethod(class, property _ "RExec", .handle, parentId)
    set children = ""
    for {
        set sc=$classmethod(class, property _ "RFetch", .handle, , .ids, .returnCount, .atEnd)
        quit:(returnCount=0)
        set children = children _ ids
        quit:atEnd
    }
    return children
}

Enchantments

Here's some points on how the code can be expanded:

  • Export streams
  • Search for property references to this object
  • Specify number of levels

Links

Have you encountered the same problem? If so, how have you solved it?

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