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.

UI Macro button redirect URL not working

dlj23
Kilo Explorer

Hi,

 

I created a UI Macro button that's supposed to redirect to a new table, but it doesn't seem to work. It somehow always attempts to create a new incident record instead.

 

So I created a new macro with the following code:

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<button onClick="return testF();"> Edit </button>
<script>
function testF()
{
window.location = 'u_test_table.do';

}
</script>
</j:jelly>

 

u_test_table is the new table I created.

 

I created a new formatter that uses this macro and added that to the incident table.

 

When I open an incident and I click on the button, it actually creates a new incident record. I know it does the redirection as well because if I changed it to:

 

window.open() instead, it does open a new tab to the new table, but the current location also creates a new incident record.

 

Is there something I'm missing? I don't want it to create a new incident record, just redirect to the new url.

 

Thanks.

1 ACCEPTED SOLUTION

Ashok10
Mega Expert

Jason,


This time it should work. Please try change your script part



<script>
function testF()
{
window.location = '/u_test_table.do';
return false;


}
</script>



That is add return false; after redirection.


View solution in original post

7 REPLIES 7

how would I use this method to create a new record with set values, then redirect to it? much like the UI Action "action.setRedirectURL(current)"?



when trying to save the UI macro, it doesn't like the "sysparm_query" being in the URL.


find_real_file.png


Try this link for sysparm_query error message


https://community.servicenow.com/thread/208784


Artemis15
Kilo Guru

Please use the following:


var url = "https://"+window.location.hostname.toString()+"/u_test_table_list.do";


              window.open(url, "_self");