$Order and $Next in Cache Basic script
Hi all,
I need to create a routine to modifiy some values in a global.
My first attempt was:
set pos=$Order(^Ens.MessageBodyD(""))
while(pos > 0){
// Get the class name
set clase = $Order(^Ens.MessageBodyD(pos,1))
if (clase="MensajesRestResponse")
{
// Do the convertion
}
set pos = $Next(^Ens.MessageBodyD(pos))
}
but if I use a *.bas file (cache basic script), I'm not able to use these commands ($Order and $Next) and I don't know how to translate theses words.
please, could the comunity help me?
My goal is convert the content of the message (old mesages) from %String to %Stream.GlobalCharacter because now there are some values in string and other are on Stream.GloablCharacter and there is not match in ^Ens.MessageBodyS for these messages.
Best regards,
Francisco Lopez
Comments
Why do want to use basic for that?
You want to use the FOR EACH syntax or the TRAVERSE function which is the equivalent of $ORDER. Here is a link to the documentation online
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY…
Generally not good practice to mix $order and $next. $next uses -1 for "end of set", which of course is a valid global subscript. $order uses the null string, which on almost all Cache instances out there is not valid.
Also, this line:
set clase = $Order(^Ens.MessageBodyD(pos,1))
Should probably be this although I doubt this actually works: you need to use $listget(clase,1) or something similar:
set clase = $Get(^Ens.MessageBodyD(pos,1))
And test for the While loop exit should be:
while (pos'="")
However, I would stay away from direct global access unless you really need it. Stick to SQL for querying/updating , or objects for updates.
HTH
andre