Service portal basics - how do I print data from a server query in a widget

Salzo
Giga Contributor

Im trying to output a list in the service portal but at the moment nothing is being returned. The questions is I know the server script is returning values but how do I access them in the HTML of my widget

 

this is my html

 <div>
      <ul>
        <li ng-if="c.data.list.length > 0" ng-repeat="item in c.data.list">{{::todo.title}}</li>
      </ul>
</div>

 

this is my server side script - Ive used logs to confirm the query returns values.

var getTodos = new GlideRecord('u_todo');
getTodos.orderByDesc('u_order');
getTodos.setLimit(5);
getTodos.query(); 

data.list = [];

while(getTodos.next()){
	var todo = {};
	
	gs.info("|>>>before" + getTodos.getDisplayValue('u_title') + " " + getTodos.getDisplayValue('u_url'));


	
	todo.title = getTodos.getDisplayValue('u_title');
	todo.url = getTodos.getDisplayValue('u_url');
	gs.info("|>>>after" + todo.title + " " + todo.url);
	
	data.list.push(todo);
	
	
}
1 ACCEPTED SOLUTION

Salzo
Giga Contributor

I fixed this 

 

<ul>
<li ng-if="c.data.list.length > 0" ng-repeat="item in c.data.list">
<a href="{{::item.url}}"><i class="fa fa-chevron-right m-r-sm"></i> {{::item.title}}</a>
</li>
</ul>

View solution in original post

3 REPLIES 3

Salzo
Giga Contributor

I fixed this 

 

<ul>
<li ng-if="c.data.list.length > 0" ng-repeat="item in c.data.list">
<a href="{{::item.url}}"><i class="fa fa-chevron-right m-r-sm"></i> {{::item.title}}</a>
</li>
</ul>

Barrilito van D
Kilo Guru

Hi Salzo.

Good to see you solved your own question 🙂

Perhaps it would be even better to move the ng-if to the <ul> and do the check there. That way the <ul> will not be put in your page at all if the array has no items to show 🙂

Good luck!

Barrilito van D
Kilo Guru

btw, as your question was answered by yourself, set your answer as best answer so that others can see the question was answered, because I looked at your question thinking it was not answered as well. Thanks!