No problem mate. I have been working on a couple of scripts that do this. They create Xpath and Regexp custom columns. The Config is a JSON object that I store in a global variables.
This Regexp is fully functional and does all those things. Regexp Columns
This xpath script is a work in progress. XPath columns
The bit you care about is this.
var doVars = DOpus.vars;
var xmlKey = "XmlCustomColumnsConfig";
function SaveCustomColumns(customColumns){
var newList = new Array();
for(var i = 0; i < customColumns.columns.length; ++i) {
if(customColumns.columns[i]) {
newList.push(customColumns.columns[i]);
}
}
customColumns.columns = newList;
var config = JSON.stringify(customColumns, undefined, 2).replace(/(\n)+/g,"\r\n");
doVars(xmlKey) = config;
doVars(xmlKey).persist = true;
}
function LoadCustomColumns(){
var config = doVars.Exists(xmlKey) ? JSON.parse(doVars.Get(xmlKey)) : null;
if(!config)
{
config = defaultCustomColumns;
}
return config
}
This script will help to see what is in the global variables.
global-variable-management-dialog