Question
· Jun 27, 2019

Is it possible to save a class in another namespace?

Hi 

Quick question... Is it possible to save a class in another namespace. If you're saving a global you can just use an extended reference, but is it possible to achieve the same when saving a class object?  Obviously the class will be defined in the other namespaces too.

I want to do it from an Ensemble SOAP Service. I guess you could switch namespaces, but I was a bit worried about doing that from Ensemble process.

thanks

Discussion (7)2
Log in or sign up to continue

Does your suggestion just switch namespace? 

We will be receiving events to a central SOAP service for a number of 'sites' on the same machine in different namespaces. They share a common database, but some globals are not mapped to the central database namespace so as to separate out some settings and they also need to take responsibility for resolving data issues for the patients belonging to their area.  

The SOAP service will upload events automatically for individual patients, but each 'site' only wishes to see events related to their patients and manually resolve 'rejections' for their area.  I think in explaining the case, I have thought of another way to do it. I think I will save the object centrally and just save a namespace specific global which points to ones for their area, then I can also create an index by 'site'.  I think that should do it.  

thanks for your suggestions!

Any of the following is possible, but this will only work if you want to keep the data in the two namespaces for that class exactly the same : 

  • Map the globals that are used by the persistent class to the other namespace.

OR

  • Change the global names in the Class Storage definition (DataLocation, IDLocation, IndexLocation, StreamLocation) and add a namespace reference to it, like this :
Storage Default
{
<Data name="customerDefaultData">
...
<DataLocation>^["USER"]test.customerD</DataLocation>
<DefaultData>customerDefaultData</DefaultData>
<IdLocation>^["USER"]test.customerD</IdLocation>
<IndexLocation>^["USER"]test.customerI</IndexLocation>
<StreamLocation>^["USER"]test.customerS</StreamLocation>
<Type>%Library.CacheStorage</Type>

Be careful if properties are pointing to other persistent classes as well !

Hello,

If you need to save your class in more than 1 namespace, and you are using studio, you may do it automatically with studio hooks.

This is done in that way:
1. You create your own source control class which inherit from %Studio.SourceControlBase
2. you put your code in that class. For example you may use OnAfterSave method to run on all namespaces that your class need to be saved, loop on this list (except the current one of course) and save + compile your class (programmatically) in each namespace. 

https://irisdocs.intersystems.com/iris20191/csp/docbook/DocBook.UI.Page.cls?KEY=GSTD_Intro#GSTD_intro_schooks

https://irisdocs.intersystems.com/iris20191/csp/documatic/%25CSP.Documatic.cls?APP=1&LIBRARY=%25SYS&CLASSNAME=%25Studio.SourceControl.Base