Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get URL in Agent Workspace

Maddalena Mores
Kilo Expert

Hi, 
in Agent Workspace I created a Related List Action implemented as Server Script.

I wolud like to get the URL. I tried with gs.action.getGlideURI() and I recieved this string: api/now/v1/batch?api=api, but I need to recieve the URL string like this: /now/workspace/agent/record/rm_release/3b682b1bdbc2d850ceb3ef08489619aa.

 

How can I do that?

 

Thanks in advance
Maddalena

7 REPLIES 7

Unfortunately, No. 😞

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

Thomas Wright1
Tera Contributor

Try using:

GlideTransaction.get().getRequest().getHeader("Referer")

This prints out the entire URL, and works on the workspace as well as "normal" view. I used this to figure out which page I was on for a before query business rule.

 

I'm not sure if this works in a scoped app, but it worked for me running in a Global business rule on Utah

Found this code being used in the global.InteractionRelationshipUtil script include, in the getParentInteractionSysId method

/**
 * Utility to fetch sys_id of parent interaction record by using URL in request
 */
getParentInteractionSysId: function(){
	var txn = GlideTransaction.get();
	if (!txn)
		return;
	var request = txn.getRequest();
	if (!request)
		return;
	var referer = request.getHeader("Referer");
	if (GlideStringUtil.nil(referer))
		return;
	var matches = referer.match(/\/(agent|sow)\/(chat|record\/interaction)\/([0-9a-f]{32})/);
	if (!matches || matches.length < 4)
		return;
	return matches[3];
},

@JagjeetSingh @AgatheL @ayanc27 

This works, we needed to show a UI Action in configurable workspace, but hide it from Agent Workspace and the only way we could figure out how to do that was by evaluating the URL.