Daniele Songini
Tera Guru

Hi,

I created a script that allows you to open the scripts include directly from the code.
To open the link, use ctrl + click.

This example is on Business rule table.

This is the final result:

find_real_file.png

This is the necessary script:

Client script on load, on Business rule table

function onLoad() {

	try {

		setTimeout(function(){
			
			// Get all elements with class "cm-variable"
			var scriptInclude = g_form.getFormElement().getElementsByClassName('cm-variable');
                        
			for(var i = 0; i < scriptInclude.length; i++) {
				
				var fName = scriptInclude[i].innerHTML;
				
				// Retrieve the Script include
				var si = new GlideRecord("sys_script_include");
				si.addQuery("name",fName);
				si.setLimit(1);
				si.query();
				
				// Generate the link and update html
				while(si.next()){
					scriptInclude[i].innerHTML = '<a href="/nav_to.do?uri=sys_script_include.do?sys_id='+si.sys_id.toString()+'">'+fName+'</a>';
				}

			}

		}, 3000);

	} catch(exception) {
		jslog('Error in Client Script <script>: ' + exception);
	}

}

Notes
- Client script on load and not onChange, to avoid performance issue.
- Timeout of 3s necessary, because without it some times script field is loaded after the client script.
- Remember to press Ctrl before the click

I hope it's useful!
Corrections and comments are welcome 🙂

Daniele

Comments
rigonriccardo
Kilo Contributor

Very useful!

 

I wonder if you can avoid the scratchpad business rule, and remove the _blank target for the link, with the same result...

Daniele Songini
Tera Guru

Updated as suggested!
Many thanks Riccardo

Narendra Kota
Mega Sage

Nice, and wonderful one.

Chris D
Kilo Sage
Kilo Sage

Stumbled on this looking for something else, but in case anybody else does in the future, this functionality is now provided ootb for all code editors - you just right-click the script include in your code > Open Definition:

ChrisD_0-1728572684818.png

 

Nice work to OP for coming up with this alternative, presumably before it was offered ootb - I've used the ootb feature a thousand times and it really is very valuable.

Version history
Last update:
‎07-05-2019 03:27 AM
Updated by: