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

yea tried 😞

Shweta KHAJAPUR
Tera Guru

As you are directly using the data.announcement in HTML, it'll try to fetch the once the form load. Try something as below for testing purpose,

(function() {
data.announcement = 'test';
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
}
})();

Omkar Mone
Mega Sage

Hi 

Got it , Try the below in Server Side Script :- 

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	var arr=[];
	var announce=new GlideRecord('announcement');
announce.addQuery('active=true');
announce.query();
while(announce.next()){
arr.push( announce.name); 
}
data.announcement = arr.toString();
})();

 

HTML (same):- 

 

<div>
<!-- your widget template -->
  <marquee>{{data.announcement}}</marquee>
</div>

Thank you so much.Its working fine. how can I use ng-repeat here to split the values?

Hi 

Something like :- 

ng-repeat="announcement in data.announcement"

now here announcement will be your iterator like in for(var i=0;i<something;i++) "i" is your iterator.