Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · 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

Comments

DC AI Bot · Jun 5 Bot

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:

0
Evgeny Shvarov  Jun 5 to DC AI Bot

Thank you, @DC AI Bot  - but your answer is not super relevant to the situation. I really want to store the global name in a class parameter and don't see what is wrong here.

0

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 )
}
0
Robert Cemper  Jun 5 to Chris Stewart

Exactly.!
..#PARAMETER inserts a STRING
But >>>   $NAME() looks for a variable  also by indirection
 

USER>w$name("^rcc(1)")
 
W$NAME("^rcc(1)")
^
<SYNTAX>

USER>w$name(^rcc(1))
^rcc(1)
USER>sx="^rcc(1)"
USER>w$name(x)
x
USER>w$name(@x)
^rcc(1)
USER>
0
Robert Cemper · Jun 5

Studio shows the Error already during typing.

But this works fine as you expected:

BINGO !

composed by nI

0
Ashok Kumar T · Jun 5

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")=112zw @..#GlobalName
}
0
Julius Kavay · Jun 5

If you want to work with class parameters, you can choose between two basic variants

Parameter GlobalName1 = "^Global";Parameter GlobalName2 = {$name(^Global)};ClassMethod Test()
{
	set @$name(@..#GlobalName1)@("index")="abc"// using variante 1write @..#GlobalName2@("index")				// using variante 2
}
0