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 call server side data on html side?

Sin
Giga Expert

Guys am trying to show `name` field from `announcement` table on html side using `<marquee></marquee>` field.

Server script: 

(function() {

var announce=new GlideRecord('announcement');
announce.addQuery('active=true');
announce.query();
while(announce.next()){
data.announcement= announce.name;
console.log(data.announcement);// got data here
}
})();

 

HTML code:

<div>

<marquee>{{data.announcement}}</marquee>

</div>

 

I am not getting the data on html code. What I did wrong here?

If I have multiple datas on name field how can I loop it?

1 ACCEPTED SOLUTION

Sin
Giga Expert

The following code worked me for showing marquee data from array and object.

serverside:

 

(function() {
data.arr = [];
var announce=new GlideRecord('announcement');
announce.addQuery('active=true');
announce.query();
while(announce.next()){
var record={};
var display_value='';
display_value = announce.getValue('name') ;
record.display_field=display_value;
data.arr.push(record);
}

})();

 

Html side:

 

<div>
<marquee><b ng-repeat='val in data.arr'><label>{{val.display_field}}</label></b></marquee>
</div>

View solution in original post

13 REPLIES 13

No its not working because 'data.announcement' is a string right? How can i call 'arr[]' from server side to client side? if we store 'arr[]' in a '$scope' ,then it will be easy to use ng-repeat right? when I tried with '$scope.val=c.arr' on client side it returns nothing.

Hi 

In this case you can return the length of array.

Hi 

Please post a new question  as this thread is closed, also your question is new. Thanks

Sin
Giga Expert

The following code worked me for showing marquee data from array and object.

serverside:

 

(function() {
data.arr = [];
var announce=new GlideRecord('announcement');
announce.addQuery('active=true');
announce.query();
while(announce.next()){
var record={};
var display_value='';
display_value = announce.getValue('name') ;
record.display_field=display_value;
data.arr.push(record);
}

})();

 

Html side:

 

<div>
<marquee><b ng-repeat='val in data.arr'><label>{{val.display_field}}</label></b></marquee>
</div>