@mwraâI found what was causing this behavior with your script. It seems that the attribute operator returns data structures that might have changed at some point. In a nutshell, the âsuggestedâ string returned by the attribute() operator is a list with items separated by semicolons, not colons. I assumed this would be different if all of the configuration items for an attribute were retrieved as a dictionary, but that turns out to not be the case. Due to the conflicting interpretation of semicolon delimiters, the keys for the dictionary extend to each suggested string after the first.
While it makes sense for the data structure returned for âsuggestedâ to be a list, that makes it incompatible with the dictionary structure. The lesson Iâm taking away from this is, donât bother retrieving the entire dictionary of an attributeâs configuration. Instead, retrieve each individual configuration item separately. Specifically, string types for type, default, and description, and list type for suggested.
If youâre interested, full details of my experimentation and analysis are presented in the summary.
Summary
Here is the script you provided as an example in response to the original post, but with some LogRec calls inserted to log what was going on when this script executed. The revised script looks like this:
// Example: Capture User Attribute details by Mark Anderson
// First, declare a variable vAttrList to hold the list
// of user attribute names
var:list vAttrList = document ["user-attributes"];
LogRec(StampLog,vAttrList);
// Clean out $Text. We overwrite anyway, but, safety first...
$Text=;
// Next, we report the number of items in the
// list stored in variable vAttrList
$Text = "Number of user attributes: "+ vAttrList.count+" \n";
// Now we iterate (loop) through vAttrList's items
// We declare 'anAttr'as our loop variable, i.e. the
// value of the vAttrList item currently being used in-loop
vAttrList.each(anAttr)
{ // For each attribute, we say what the attribute is called
// i.e., the current value of the anAttr loop variable
LogRec(StampLog,anAttr);
$Text = $Text + "\n" + anAttr + "\n";
// then we make a new variable to fetch the Dictionary of
// attribute () info for the current value of anAttr
var:list vAttrKeys = attribute(anAttr);
LogRec(StampLog, vAttrKeys);
// Now a nested loop to read each discrete key: value
// pair for the attribute name held in anAttr
// "aSetting" is declared as the loop variable
vAttrKeys.each(aSetting)
{ // report the 'key: value' pair, but placing a single space
// character after the colon for readability
LogRec(StampLog," => "+aSetting);
$Text = $Text + "\t" + aSetting.replace(":",": ")+"\n";
// close the inner loop
};
// close the outer loop
};
// The end
When this was put in a stamp, and the stamp executed with an empty note selected, the output was the same as what you encountered previously where each âsuggestedâ entry was on a separate line, as illustrated here:
Number of user attributes: 7
AnAttributeString
category: User
sequential:
default: blank
type: string
suggested: String-1
String-2
String-3
description: A string for holding attribute details.
The log output provided the clue as seen here:
Log book <StampLog> created Fri, 21 Jan 2022 22:23:00 -0500
00001 | AnAttributeString;DatestampLogs;IndexLogs;LoggingEnabled;Test_1;Test_2;TimestampLogs
00002 | AnAttributeString
00003 | category:User;sequential:;default:blank;type:string;suggested:String-1;String-2;String-3;description:A string for holding attribute details.
00004 | => category:User
00005 | => sequential:
00006 | => default:blank
00007 | => type:string
00008 | => suggested:String-1
00009 | => String-2
00010 | => String-3
00011 | => description:A string for holding attribute details.
The 00003 log entry above shows what was placed into vAttrKeys, which is the complete dictionary for the indicated attribute as produced with this code:
var:list vAttrKeys = attribute(anAttr); LogRec(StampLog, vAttrKeys);
In the log record at index 00003, the string associated with âsuggestedâ is reproduced here:
suggested:String-1;String-2;String-3
So, the inner loop is processing each key in the dictionary retrieved for the attribute. However, since the entries for âsuggestedâ are delimited by semicolons, after the first entry, the others look like new keys, which is why these were printed on multiple lines.