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.

how can redirect to external URL from script while creating button

manojlakshmanas
Kilo Expert

i need user to redirect to external page while clicking button.

1 ACCEPTED SOLUTION

manojlakshmanas
Kilo Expert

Hi


while pointing user to external URL page from UI Action client script this will be helpful to redirect.



        location.href = ("external page URL");


View solution in original post

21 REPLIES 21

Thank you Mayur,



This has worked perfectly fro me.


My requirement was to redirect to an external URL in a new tab via a UI Action.   The URL was being stored within a field on the form.



For others trying to replicate this functionality please see the below:



Client (tick box): true


Onclick: clicked()



Script:



//function must include the value added to the Onclick field as above


function clicked(){


//grab the value of the field containing the url


// ***Note*** current. syntax will not work with Client (tick box) = true


  var uplink = g_form.getValue('u_upload_link');


//set the redirect to the variable above


  window.open(uplink);


}


Mihir Mohanta
Kilo Sage

Hi Manoj,



Can you provide screenshot of the UI action you have written ?



Thanks,


Mihir


1st.jpg2nd.jpg


this is what is tried in the script while creating a button in incident from


Hi Manoj,



Window is blocked for scoped application. Please go through the below blog for more info.


Scoped Applications and Client Scripts: A Primer


Hi Manoj,



Instead of writing window.open(URL);



use



window.location=URL;





Please mark correct/Helpful if it helps.



Thanks,


Mihir