Data Preview from Server Side to HTML
Server Side Script can query any particular table and that data can be show to to HTML side with nicely HTML & CSS code.
For data server side, use GlideRecord and Script Include to Query the data.
After receiving the data we must be pass store to any variable and that variable data can be set to data.variable_name.
In HTML side use angular js syntax to bind the data- {{data.variable_name}}
Today’s Class Code:
HTML
<div>
<!-- your widget template -->
Hello {{data.fname}},
Last task oppend by {{data.task}}
</div>
Server Side Code
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var usr = gs.getUserID(); // sys_id
var grusr = new GlideRecord('sys_user');
if(grusr.get(usr)){
data.fname = grusr.getValue('first_name');
var grtask = new GlideRecord('task');
grtask.addEncodedQuery('opened_by='+grusr.getValue('sys_id'));
grtask.orderByDesc('sys_created_on');
grtask.query();
if(grtask.next()){
data.task = grtask.getValue('number');
}
}
})();