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 to get the url from server side to HTML part in a widget?

Swati44
Kilo Expert

Hi All,

Based on some conditions am changing URL on server side, Now i need to pass the same URL to html part where currently hard coded value is there.

Server side:
if(condition1)
    data.url=/incident_list.do
else
   data.url=/problem_list.do

HTML:
onclick="window.location.href=/incident_list.do"

I need to replace the same html with:
onclick="window.location.href={{data.url}}"
Which is not working, values will be sometimes /incident_list.do and sometimes /problem_list.do any idea where am doing wrong. 

Thanks in Advance.

2 REPLIES 2

Harish KM
Kilo Patron
Kilo Patron

Sample code to use URL in HTML

<li ng-if = "data.url == /incident_list.do">
<a href="/incident_list.do>Incident</a>
</li>

Regards
Harish

Oleg
Mega Sage

I'm mot sure that I correctly understand your problem, but I suppose that you should use ng-click instead of onclick in HTML code of the widget. The value of ng-click should be call of some function defined in the Client Controller like ng-click="c.myredirect()". Finally you should include $window in the list of parameters of Client Controller and the code of myredirect function could look like the following:

c.myredirect = function () {
	$window.location.href = c.data.url;
};

In the most cases one uses $location service instead of $windows (if the destination URL should be inside of portal), but the above code is mostly close to your original code and it should work with all URLs.