Question
· Jun 5

$Name from a parameter

Hi IRIS experts!

I have a parameter in a class that stores a global name:

Parameter GlobalName = "^AGlobal";

then I'm trying to call it as:

set gn=$name(..#GlobalName)

to use it later as:

set @gn@("index")="value"

But! I'm having syntax at set gn=$name(..#GlobalName)

What am I doing wrong?

Product version: IRIS 2025.1
Discussion (11)4
Log in or sign up to continue

The syntax issue with your line set gn=$name(..#GlobalName) likely stems from the improper use of # and the .. syntax to reference the Parameter value stored in your class. The $NAME function in ObjectScript returns the canonical name value of a variable or portion of a subscript reference. However, it works correctly only with properly defined references [1].

To resolve your problem:
1. Ensure that GlobalName is correctly defined in your class as a Parameter so it can be referenced.
2. When calling $NAME, use proper syntax for object property or parameter references. If GlobalName is a class parameter, replace ..#GlobalName with the evaluated value or other valid syntax that provides the global name string to $NAME.

The $NAME function returns a canonical name of a variable or subscripted reference, allowing you to subsequently use the @ indirection operator on the resulting string [1][2]. Here's a simplified example:

set gn=$name(^AGlobal)
set @gn@("index")="value"

Make sure ^AGlobal corresponds to the actual global structure you intend to modify or reference [1][2]. If rephrased, or if a specific class definition is missing, additional context might be required.

Sources:

It doesn't look like you are doing anything wrong but there must be something in the compiler that doesn't like you.

$Name hates class parameters but seems OK if you @ it

Parameter GlobalName = "^Glob(1)";

ClassMethod TestG() As %String [ ProcedureBlock = 0 ]
{
G=..#GlobalName
 // This only compiles when ProcedureBlock=0
$Name(G)
 
// This will not compile 
; s GN=$Name( ..#GlobalName )
// But this does and it works
 Q $Name( @..#GlobalName )
}

Hello @Evgeny Shvarov 

We can define the global name using either a compile-time class parameter or a runtime expression (COSEXPRESSION):

  • Compile-time:
    Parameter GlobalName = {$NA(^AGlobal)};
  • Runtime (COSEXPRESSION):
    Parameter GlobalName As COSEXPRESSION = "$NA(^AGlobal)";

Instead of assigning just the global name to the parameter and then later generating the full reference using $NAME, you can directly assign the full $NA(^AGlobal) expression to the parameter.

This eliminates the need to do something like:
set gn = $name(..#GlobalName)

Parameter GlobalName As COSEXPRESSION = "$NA(^AGlobal)";

Parameter GlobalName1 = {$NA(^AGlobal)};

ClassMethod SetGbl()
{
	Set @..#GlobalName1("test")=112
	zw @..#GlobalName
}