You need to change your cursors names, use two different names in your declare statements, try it.

Some considerations about embedded SQL cursors:

1) I think using embedded SQL Cursors is a practice to be avoided in favor of %SQL.Statement class usage: 

https://docs.intersystems.com/iris20232/csp/docbook/Doc.View.cls?KEY=GSQ...

2) Genarally is not  a good idea to have the same name in embedded SQL cursors, even if they are in different Methods, this because of the behaviour of the Stack separations used by the embedded SQL cursors.

3) Use a close statement before every open statement of embedded SQL cursors, this prevent problems if your process crash and in the same context you re execute it.

It works also for me... maybe it depends on how Michael Wood is passing the json object to the method... 

If he is passing a string, there is a conversion needed from string to %DynamicAbstractObject like:

Set str="{""prio"":""2"",""code"":""A001""}"
Write str
{"prio":"2","code":"A001"}
Set obj=##Class(%DynamicAbstractObject).%FromJSON(str)
Write obj
1@%Library.DynamicObject
ZW obj
obj={"prio":"2","code":"A001"}  ; <DYNAMIC OBJECT>

Yes or something like :

  • my.test.cls (original class)
  • my.test.check1.cls  (Method 1)
  • my.test.check2.cls  (Method 2)

To do so I've added:

Set destPackage=""
if ($length(cls,".")>1),$length($translate($piece(cls,".",2,99),".")'="") set destPackage=$Piece(cls,".",2,999)
//[some code]
set $piece(tmp,".",*)=destPackage_"."_met.Name		// create a new classname

Hi, in order to do that you need to create a resource first (see: https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI...), assign that resource to your application (see: https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI...) and or zen page (see: https://docs.intersystems.com/ens201817/csp/docbook/Doc.View.cls?KEY=GZA... ) then assign this resource to your role (see: https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI...) and then assign this role to your users.

Hope this can help

Hi Mark,

 in my experience mixed indexes (both with pure numbers and strings) are not a good choice if you need to perform something like a "STARTSWITH" function. 

In order to be able to always find your matching records near one to another and speed up the search, I think you have to normalize all the values by adding the space suffix to every code, assuming that values with and without space at the end refer to the same entity.
This way you can easily search for all the occurrence of a code that is starting with a specified prefix, without reading extra lines from the global.

Also you have to add a space at the prefix variable when searching if it is not present at the end of the passed value.

But if i look at your first screen, looks like you have no pure numbers in the second subscript of the global at the moment so I do not get the point.. 

Following you can find some of my tests:

d INIT^TESTRTN
^WK3SORT(1,0,9999)=""
^WK3SORT(1,801,307077)=""
^WK3SORT(1,802,306650)=""
^WK3SORT(1,800999,311404)=""
^WK3SORT(1," ",43017)=""
^WK3SORT(1," ",161692)=""
^WK3SORT(1," ",161693)=""
^WK3SORT(1," ",209576)=""
^WK3SORT(1,"80094NMGM ",528126)=""
^WK3SORT(1,"800999 ",305403)=""
^WK3SORT(1,"800999 ",305404)=""
^WK3SORT(1,"800999 ",311403)=""
^WK3SORT(1,"800999/T51316 ",364551)=""
^WK3SORT(1,"800999CAMDEN ",356252)=""
^WK3SORT(1,"801 ",307076)=""
^WK3SORT(1,"801 ",555780)=""
^WK3SORT(1,"80110 ",479476)=""
^WK3SORT(1,"802 ",306649)=""

d NORMALIZE^TESTRTN(1)
4 Lines Converted
^WK3SORT(1," ",43017)=""
^WK3SORT(1," ",161692)=""
^WK3SORT(1," ",161693)=""
^WK3SORT(1," ",209576)=""
^WK3SORT(1,"0 ",9999)=""
^WK3SORT(1,"80094NMGM ",528126)=""
^WK3SORT(1,"800999 ",305403)=""
^WK3SORT(1,"800999 ",305404)=""
^WK3SORT(1,"800999 ",311403)=""
^WK3SORT(1,"800999 ",311404)=""
^WK3SORT(1,"800999/T51316 ",364551)=""
^WK3SORT(1,"800999CAMDEN ",356252)=""
^WK3SORT(1,"801 ",307076)=""
^WK3SORT(1,"801 ",307077)=""
^WK3SORT(1,"801 ",555780)=""
^WK3SORT(1,"80110 ",479476)=""
^WK3SORT(1,"802 ",306649)=""
^WK3SORT(1,"802 ",306650)=""

d FIND^TESTRTN(1,"8009 ")
Order: 1-80094NMGM
  Detail: 528126
Order: 1-800999
  Detail: 305403
  Detail: 305404
  Detail: 311403
  Detail: 311404
Order: 1-800999/T51316
  Detail: 364551
Order: 1-800999CAMDEN
  Detail: 356252
 
5 lines read
TESTRTN
INIT
	//Create some data
	Kill ^WK3SORT
	//Strings
	Set ^WK3SORT(1," ",43017)=""
	Set ^WK3SORT(1," ",161692)=""
	Set ^WK3SORT(1," ",161693)=""
	Set ^WK3SORT(1," ",209576)=""
	Set ^WK3SORT(1,"80094NMGM ",528126)=""
	Set ^WK3SORT(1,"800999 ",305403)=""
	Set ^WK3SORT(1,"800999 ",305404)=""
	Set ^WK3SORT(1,"800999 ",311403)=""
	Set ^WK3SORT(1,"800999/T51316 ",364551)=""
	Set ^WK3SORT(1,"800999CAMDEN ",356252)=""
	Set ^WK3SORT(1,"801 ",307076)=""
	Set ^WK3SORT(1,"801 ",555780)=""
	Set ^WK3SORT(1,"80110 ",479476)=""
	Set ^WK3SORT(1,"802 ",306649)=""
	//Numbers
	Set ^WK3SORT(1,0,9999)=""
	Set ^WK3SORT(1,801,307077)=""
	Set ^WK3SORT(1,802,306650)=""
	Set ^WK3SORT(1,800999,311404)=""
	//Show content
	zw ^WK3SORT
	Quit
NORMALIZE(Sub)
	New (Sub)
	Set (cnt,End)=0
	Set Next=""
	Set Next=$Order(^WK3SORT(Sub,Next))
	While (Next'="")&(End=0) {
		//Check if code is pure number
		If (Next=+Next) {
			Merge ^WK3SORT(Sub,Next_" ")=^WK3SORT(Sub,Next)
			Kill ^WK3SORT(Sub,Next)
			Set cnt=$I(cnt)
		} Else {
			Set End=1
		}
		Set Next=$Order(^WK3SORT(Sub,Next))
	}
	Use 0 Write cnt_" Lines Converted",!
	//Show content
	zw ^WK3SORT
	Quit
FIND(Sub,Prefix)
	New (Sub,Prefix)
	//Setting the space char to normalize the search
	If $Extract(Prefix,$Length(Prefix))'=" " Set Prefix=Prefix_" "
	//Dealing with exact match
	If $Data(^WK3SORT(Sub,Prefix)) {
		Use 0 Write "Order: "_Sub_"-"_Prefix_" ",! 
		Do GETDETAILS(Sub,Prefix)
	}
	//Looping trough the records
	Set End=0,Cnt=0
	Set Next=$Order(^WK3SORT(Sub,Prefix))
	While (Next'="")&(End=0) {
		Set cnt=$Increment(cnt)
		//Test if current value starts with the Prefix string passed or if it is a single space char
		If ($Extract(Next,1,$Length(Prefix)-1)=$Extract(Prefix,1,$Length(Prefix-1)))!((Prefix=" ")&(Prefix=Next)) {
			Use 0 Write "Order: "_Sub_"-"_Next_" ",!
			Do GETDETAILS(Sub,Next)
		} Else {
			Set End=1
		}
		Set Next=$Order(^WK3SORT(Sub,Next))
	}
	Use 0 Write !,cnt_" lines read",!
	Quit
	//Extract detils subscripts
GETDETAILS(Sub,Ord)
	New (Sub,Ord)
	Set Det=""
	Set Det=$Order(^WK3SORT(Sub,Ord,Det))
	While Det'="" {
		Use 0 Write "  Detail: "_Det,!
		Set Det=$Order(^WK3SORT(Sub,Ord,Det))
	}
	Quit