Question
· Apr 15, 2020

Declaring a variable in a class that a routine will recognize

Hello all,

I'm new to the Intersystems development world and I've been trying to figure out how to make a REST API using ObjectScript. I found a tutorial that I've been following that has been great and I'm trying to translate what I've learned to live data.

My question is "Is there a way I can set a variable inside of a class so when I call a routine that variable will be recognized?" I'm capable of setting the variable in a terminal session and then calling the routine and everything will be work great! I will get the data I want returned. I'm just not capable of getting this to translate when I'm calling the routine from a class.

Here is my code: 

  ClassMethod GetSites() As %Status
{
SET %response.ContentType = "application/json"
SET returnObject = {}
SET returnMessage = "Sites have returned successfully"
SET returnObject.message = returnMessage
//
SET = "^"
DO SITES^BGOQRPT(.SITES,"")
SET key=$ORDER(SITES(""),-1)
SET sitesArray = []
FOR i=1:1:key {
SET sitesObject = {}
SET sitesObject.id = i
SET sitesObject.siteNumber = $P(SITES(i),U,1)
SET sitesObject.siteName = $P(SITES(i),U,2)
DO sitesArray.%Push(sitesObject) }
SET returnObject.sites = sitesArray WRITE returnObject.%ToJSON()
QUIT $$$OK
}

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