Article
· Aug 10, 2023 3m read

Remote Global Listing using NativeAPI for ObjectScript #1

This question originally appeared in the comments of the post: Download globals from a particular server
 

This article was inspired by a recent question from @Evgeny Shvarov 
Download globals from a particular server

It is not a click-and-run code but a draft that requires adjustments for your special needs
you have  to add 

  • your credentials for server access
  • your level of error handling
  • Global name
  • the first set of subscripts as  %LB() block default=""
  • the last set of subscripts as  %LB() block default=""
  • a new global name if required default="" >> name not changed

If nothing than the global name is provided the result is a pure copy.

Warning: 
This code runs rather slowly and creates a lot of network traffic
Background As $QUERY is not supported by Native API  it is a rather
long and boring workaround with IsDefined (aka $DATA) and GetNext (aka $ORDER)

Advantage:
With this approach, there is NO need for any other code or adjustment on the remote server.
And that's my only reason to publish this example

An improvement is a "work in progress". Stay tuned for #2

Class nacl.GVC
{

ClassMethod Connect(
  serverIP = "192.168.0.9",
  serverPORT = 1972,
  namespace = "USER",
  username = "_SYSTEM",
  password = "SYS") As %Net.DB.Iris
{
  try {
    set %rccon=##class(%Net.DB.DataSource).CreateConnection(serverIP
                           ,serverPORT,namespace,username,password)
    set %rccdb=%rccon.CreateIris()
    }
  catch { zw  b  }  ;; do some error handling
  quit %rccdb
}

/// tosubscript stops loop
ClassMethod View(
  global As %String = "",
  fromsubscript As %List = "",
  tosubscript As %List = "")
{
  quit ..Copy(global,fromsubscript,tosubscript,"")
}

/// rename also works to local variable array
ClassMethod Copy(
  global As %String = "",
  fromsubscript As %List = "",
  tosubscript As %List = "",
  rename As %String = "*")
{
#dim %rccdb as %Net.DB.Iris
 set subs=..Args(fromsubscript)
 set stop=..Args(tosubscript)
 set:rename="*" rename="^"_global 
loop
 if $l(subs),$l(stop),$p(subs,stop)="" quit 1 
 set gx=""""_global_""""
#; write !?20,gx_subs   just for debug
 set x1="quit %rccdb.IsDefined("_gx_subs_")"
   , dd=$xecute(x1)
 if $l(stop),subs]]stop quit 1   
 if dd#10 { 
   set x2="quit %rccdb.Get("_gx_subs_")"
     , val=$xecute(x2)
     , tx=rename_$s($l(subs):"("_$e(subs,2,*)_")",1:"")
     , tv=##class(%Utility).FormatString(val)
     , x3="(val) set "_tx_"=val q 1 "
   if $l(rename),$xecute(x3,val) write tx," = ",tv,!    
   else  write "^",global,tx," = ",tv,!  
   }
up
 set down=$s(dd\10:",""""",1:"")
 set x4="quit %rccdb.GetNext(1,0,0,"_gx_subs_down_")"
   , nxsub=$xecute(x4)
 if nxsub="" {
   set dd=0 
   if down="" set subs=$p(subs,",",1,*-1)
   goto up
   } 
 if '$isvalidnum(nxsub) set nxsub=""""_nxsub_""""
 set $p(subs,",",*+(dd\10))=nxsub   
 if $l(subs,",")<2 quit 1
 goto loop
}

ClassMethod Args(list As %List = "") As %String
{
  if '$listvalid(list) set list=$lb(list)
  set ll=$ll(list),subs=""
  for i=1:1:ll {
    set sub=$li(list,i)
      , subs=subs_","_$s($isvalidnum(sub):sub,1:""""_sub_"""")
  }
  quit subs
}
}
Discussion (1)0
Log in or sign up to continue