We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Jim Coyne
Kilo Patron

Building on the "Xplore GlideRecord Script" Tool post, the "Preview in Background Script" tool will open a new Background Script window and populate the script field with the template of code containing the list view's query:

find_real_file.png

find_real_file.png

The script will be populated 1/4 second after the Background Script window is opened in order to ensure the window has been opened properly.

All you need to do is create a new Context Menu record with the following details:

Table: Global

Menu: List Header

Type: Action

Name: Preview in Background Script

Order: 116,000

Condition: gs.hasRole("admin")

Action script:

(function u_previewGlideRecordScript(){

  var fixedQuery = ("" + g_list.getFixedQuery()).replace("null", "");

  if (fixedQuery == "") {

  fixedQuery = ("" + g_list.getRelatedQuery()).replace("null", "");

  }

  var query = fixedQuery;

  var listQuery = g_list.getQuery();

  if (listQuery != "") {

  if (query == "") {

  query = listQuery;

  } else {

  query += "^" + listQuery;

  }

  }

  var newLine = "\n";

  var script = "(function() {" + newLine;

  script += "       var gr = new GlideRecord('" + g_list.tableName + "');" + newLine;

  if (query != "") {

  script += "       gr.addEncodedQuery('" + query + "');" + newLine;

  }

  script += "       //gr.setLimit(100);" + newLine;

  script += "       //gr.setWorkflow(false);" + newLine;

  script += "       //gr.autoSysFields(false);" + newLine;

  script += "       gr.query();" + newLine;

  script += "       while (gr.next()) {" + newLine;

  script += "               " + newLine;

  script += "       }" + newLine;

  script += "})();";

  // open the Background Scripts page in a new window

  var win = window.open('/sys.scripts.do');

  //and then populate the script box a quarter second later

  setTimeout(function(){

  try{

  var textArea = win.document.getElementById("runscript");

  textArea.value = script;

  } catch(err){}

  }, 250);

})();

Related posts:

"Preview GlideRecord Script" Tool

"Xplore GlideRecord Script" Tool