0
Engaged
,
/t5/framemaker-discussions/how-do-i-create-a-user-variable-in-extendscript/td-p/15246740
Apr 02, 2025
Apr 02, 2025
Copy link to clipboard
Copied
I think the below info is correct. Let's say my user variable is named "_DocType". I can read and write and check the existence of the variable like this:
var doc = app.ActiveDoc;
// Check Exists
var varFmt = doc.GetNamedObject (Constants.FO_VarFmt, "_DocType");
if(varFmt.ObjectValid()){
alert("Variable _DocType exists!")
}
// Write Variable - as "User Guide":
var varFmt = doc.GetNamedVarFmt ("_DocType");
varFmt.Fmt = "User Guide";
// Read Variable
var varFmt = doc.GetNamedObject (Constants.FO_VarFmt, "_DocType");
alert (varFmt.Fmt);
However, I'm not sure how to create the variable if it doesn't exist yet.
Thanks in advance!
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Community Expert
,
Apr 02, 2025
Apr 02, 2025
I use something like this:
function getVarFmt (name, definition, doc) {
var varFmt;
varFmt = doc.GetNamedVarFmt (name);
if (varFmt.ObjectValid () === 0) {
varFmt = doc.NewNamedVarFmt (name);
varFmt.Fmt = definition;
}
return varFmt;
}
Note that if the variable format current exists, then the "definition" parameter isn't used.
Community Expert
,
/t5/framemaker-discussions/how-do-i-create-a-user-variable-in-extendscript/m-p/15246743#M87368
Apr 02, 2025
Apr 02, 2025
Copy link to clipboard
Copied
I use something like this:
function getVarFmt (name, definition, doc) {
var varFmt;
varFmt = doc.GetNamedVarFmt (name);
if (varFmt.ObjectValid () === 0) {
varFmt = doc.NewNamedVarFmt (name);
varFmt.Fmt = definition;
}
return varFmt;
}
Note that if the variable format current exists, then the "definition" parameter isn't used.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Marshall_Brooks
AUTHOR
Engaged
,
LATEST
/t5/framemaker-discussions/how-do-i-create-a-user-variable-in-extendscript/m-p/15246764#M87369
Apr 02, 2025
Apr 02, 2025
Copy link to clipboard
Copied
Works perfectly (as expected) - Thanks again!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

