Jim Coyne
Kilo Patron

I previously wrote a helpful little tool called "Preview GlideRecord Script" which would popup a window with the current list view's filter within a block of code:

find_real_file.png

This would allow you to copy and paste the code wherever you needed it and use it as a starting point.   I thought I'd do the same thing for James.Neale's excellent Xplore tool.   All you need to do is create a new Context Menu record with the following details:

Table: Global

Menu: List Header

Type: Action

Name: Xplore GlideRecord 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 Xplore tool in a new window

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

  //when Xplore has loaded, set the script

  jQuery(win).bind('load', function(){

      win.snd_xplore_editor.setValue(script);

  });

})();

This now adds a new context menu when you right-click a list view header:

find_real_file.png

When you select it, a new Xplore window is opened and populated with the block of code containing the list view's query:

find_real_file.png

You obviously need to install the Xplore tool itself in order for this to work and it can be found on the Share site - https://share.servicenow.com/app.do#/detailV2/bbe5dd7213e7de004e8cd4a76144b0ef/overview

Have a good weekend!

Related posts:

"Preview GlideRecord Script" Tool

"Preview in Background Script" Tool

12 Comments
Not applicable

Pretty cool, man, thanks!


Jim Coyne
Kilo Patron

You are welcome.   I just added another related post - "Preview in Background Script" Tool


BALAJI40
Mega Sage

Hi Jim,



I have seen this article very recently and you did amazing job.


Based on that, i want achieve same thing like if i click on "preview or xplore GildeRecord script" it moves to "sys_script_fix" table and want to set the same gliderecord script in script field.



So for that i have modified the above script like,


  var win = window.open('/sys_script_fix.do');// it moving to fix script form.



But i am unable to set the script with gliderecord script. SO how can we achieve this one?


conanlloyd
Giga Guru

Deleted my previous post because you had already done almost exactly what I asked for.   Consider yourself promoted from "Rockstar" to "RockGOD!"


Jim Coyne
Kilo Patron

Thanks Conan, appreciate the promotion


michael12857
Kilo Contributor

This is awesome! Thanks for much for sharing.   I was thinking recently how nice it would be to have Syntax Editor Macros in Xplore but this is a great alternative.   I use Xplore for GlideRecord operations 90% of the time anyway and this little script does the trick.



  Michael


binm
Kilo Contributor

Just a silly question: how do I install this? I tried import xml on the update set table and it's not working hahaha xD


Jace Benson
Giga Sage

You should make a pull request and add that feature imo.



GitHub - thewhitespace/Xplore: Xplore: Developer Toolkit for ServiceNow


Jim Coyne
Kilo Patron

I've attached an XML of the context menu that you can use the "Import XML" menu item to import it and the menu item should then appear.   You can use "Import XML" on any list view - the XML will be loaded into the proper table based on the contents of the XML file.



Additionally, the Xplore tool needs to be installed as well for it to work.   It can be found here if you do not have it already - ServiceNow Share


binm
Kilo Contributor

Thank you for the reply, guys! I ended up finding it in the "Retrieved Update Sets" after importing it as a xml. I just didn't see it in the "Local Update Set" and I thought I was going crazy haha.