I'm posting this as a potential solution. I imagine there are smarter ways of doing this. Hoping someone will jump in and show me the way 😁

I've written a classmethod that accepts 3 arguments: the lower and upper limits of the IDs to select, along with the number of records you'll want to select:

Class Sample.Rand
ClassMethod RandList(pMin As %Integer, pMax As %Integer, pLen As %Integer = 10) As %String [ SqlName = List, SqlProc ]
        Set tList = ""
        Set tCnt = 1
        For i=1:1:pMax
            Set tNum = $R(pMax + 1)
            If tNum >= pMin
                Set $LIST(tList,tCnt) = tNum
                Set tCnt = tCnt + 1
            Quit:(tCnt > pLen)
    Return tList

The method can be called as a custom SQL function in a subquery:

SELECT * FROM MyTable WHERE %Id %INLIST (SELECT Sample.List(MIN(%Id),MAX(%Id),10) FROM MyTable)

The query above will select up to 10 rows randomly from table MyTable.

Caveats: This could take a long time to run if your range from minimum to maximum %Id is large. And it's not guaranteed to return the number of rows specified as the 3rd argument (there may be deleted records, or insufficient random values generated before the upper limit for %Ids is reached). Finally, it assumes that %Id is numeric.

EDIT: And as pointed out by @Julius Kavay, @Robert Cemper has a better idea (he usually does 😉)

In additional experimentation, I found that there is a quoted-string mechanism:

> Set oM."click".type = "double"

is equivalent to

> Set oM.click.type = "double"

Regardless, it's still not persistent.

No, you can't use the quoted string notation (or at least if you can, I haven't figured out how).

It's not persistent either, which is why I followed up to state that it's not really what you're looking for.

You should need only to iterate over the result set and populate the repetition of the PV1 field. Note that you reference PV1.7 (attending provider) in your narrative, but your code references PV1.3 (assigned patient location), so adjust the below as needed to identify the proper field:

//create a copy of the request
Set newREQ = pRequest.%ConstructClone()
//now we use the copy for manipulation
Set res=##class(%ResultSet).%New("%DynamicQueryGW:SQLGW")
Set sc=res.Prepare(sqlstring,,conn)
Set sc=res.Execute()
// create a repetition counter
Set cnt=1
While res.Next()
    Set RET = res.GetData(2)
    //Modify the segment
    //Reference the correct repetition for the current result set member
    set res = newREQ.SetValueAt(RET,"PV1:3("_cnt_")")
    //Increment the repetition counter
    Set cnt=cnt+1
Set sc=res.Close()
Set sc=conn.Disconnect()

The appropriate repetition delimiters as defined within the message schema (in this case "~") are automatically inserted.

Note that the SetValueAt() method has been modified with the assumption that you're using a consistent HL7 schema across all messages and know the correct path to the PV1 field in question. In that case the FindSegment() method should not be necessary.

Hmm. Upon re-reading your question, I realized this isn't really the answer you were looking for. Others have provided the correct solutions/references.

ClassMethod TestObj() As %DynamicObject

        Set oM = {}
        Set mMode = ["down","up","click"]
        Set iter = mMode.%GetIterator()
        While iter.%GetNext(,.val)
            Do oM.%Set(val,{"id":"","type":""})
        Quit oM

USER> set oM = ##class(User.DynObj).TestObj()
USER> write oM.%ToJSON()
USER> zwrite oM.down.id
USER> zwrite oM.up.type
USER> set oM.click.type = "double"
USER> write oM.click.type
USER> write oM.%ToJSON()

To clarify, are you looking for a method to be used in a Business Process to obtain the path and name of a file created by a Business Operation?

For me, this was a fundamental revelation when I started working with Caché/ObjectScript. Where the $#&! is the sort function/method? I had naively assumed that arrays were simply associative with no intrinsic ordering, like Perl hashes.

When the light dawned ... 🤦‍♀️

Do you have ^EnsPortal("DisableInactivityTimeout","Portal")=1 in each namespace that's running a production? It's not mapped from another namespace.