Need to remove 'nav_to.do?' from BR constructed URL?

Julie Peters
Kilo Explorer

I want to copy variables from a custom table (like new_call) to the catalog item chosen.  I am using logic from Brad Tilton to move over the custom table sys_id in URL constructed from the Business Rule. 

https://community.servicenow.com/community?id=community_blog&sys_id=596dea29dbd0dbc01dcaf3231f96190b

I added a sysparm value to the url"+" sysparm_newcall_sysid=" + current.sys_id;

The BR constructs the URL fine and I see it with a log statement. Unfortunately, the instance adds the default 'nav_to.do?' to the URL which causes the on load client script to get a null value for my parameter.  If I manually cut and paste the URL from the log (without the nav_to.do?) the client script gets the value successfully. 

Is there a way to remove part of the default URL path, specifically the nav_to.do? 

The onload client script need to work for a Service Portal catalog item, so no document or window commands please.  Thank you!

 

 

9 REPLIES 9

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you describe a little more about what you're doing here and include the code from the business rule? What does the final url look like? 

Julie Peters
Kilo Explorer

Hello Brad, My BR is similar to others such as the New Call changed to Request.  It includes:

var sysid=current.sys_id;

var url="com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=" + reqitem+"&sysparm_newcallid=" +GlideStringUtil.urlEncode(sysid);

gs.log(url);

action.setRedirectURL(url);

So my log url looks great.  And if I manually paste it into the URL (after the instance) my onload client script returns the newcall sysid.

function onLoad() {

       //Use the 'getParameterValue' function below to get the parameter values from the URL  

       var mycall = getParameterValue('sysparm_newcallid');

       if (mycall) {

               g_form.setValue('call_record', mycall);

       }

}

function getParameterValue(name) {

       name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

       var regexS = "[\\?&]" + name + "=([^&#]*)";

       var regex = new RegExp(regexS);

       var results = regex.exec(top.location);

       if (results == null) {

               return "";

       } else {

               return unescape(results[1]);

       }

}

So the problem seems to be that the new call redirect to the catalog includes the "nav_to.do?uri=" after the instance instead of just going to /com.glide  etc.  Isn't there an easy way to redirect without that nav extension?

Thanks!!

 

You can probably do that with an absolute url like:

var url = gs.getProperty('instance_name') + '.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqitem + '&sysparm_newcallid=' +GlideStringUtil.urlEncode(sysid);

The thing you lose with removing nav_to.do?uri= is the leftnav and instance header, though. I think I've used this in the past with the nav_to.do?uri= in the url successfully but I'd need to go test that.

Good idea but no, even the hard coded adds the leftnav back.  If this were an application menu I could put window=_blank.  Is there a way to go straight to the catalog or SP view of this catalog item without the left nave included?