Updating Status and Executing Tasks using HTML and JavaScript in Reports
Use HTML and Javascript in Web Channel Reports to execute Sharperlight processes that update records or execute tasks.
In the example a Column called Completed in a SQL Table called Tasks is updated from the Web Channel report using a HTML Checkbox and Button to make a AJAX call the the RESTfull service.
SQL Database Table Tasks
CREATE TABLE [dbo].[Tasks](
-
- [Code] [nvarchar](50) NULL,
- [Description] [nvarchar](50) NULL,
- [Code] [nvarchar](50) NULL,
[Complete] [tinyint] NULL
) ON [PRIMARY]
Studio Datamodel Process SQL
update [dbo].[Tasks]
set Complete = {_Process.Args.P2}
where [Code]= {_Process.Args.Q1}
Report Expression – HTML Button and Checkbox
<div>Completed
<input type=’checkbox’ id=’c%id%’ %checked% >
<button style=’font-size:x-small;’
onclick=“JavaScript:
var completed=0;
if($(‘#c%id%’).is(‘:checked’)) completed=1;
alert(‘Set Complete to: ‘ + completed );
var d = new Date();
var url=’%rootUrl%/Process/?productcode=TestDB’
+ ‘&modulecode=TaskComplete’
+ ‘&processcode=Update&%usid%’
+ ‘&p1=’ + encodeURIComponent(‘%code%’) + ‘&p2=’ +completed
+ ‘&salt=’ + d.getTime() + ‘Z’;
var callback = {success: function(o) {
var json=o.responseText.substring(o.responseText.indexOf(‘{‘), o.responseText.lastIndexOf(‘}‘)+1);
var statusList = eval(‘(‘ + json + ‘)’);
if (statusList.errorMessage!=null && statusList.errorMessage!=”) {
alert(statusList.errorMessage);
}
else {
alert(‘Calculation completed’);
}
},
failure: function(o) {
alert(‘Failed’);
}
};
alert(url);
var request = YAHOO.util.Connect.asyncRequest(‘GET’, url, callback);
“>
Submit</button>
</div>
</ExpressStore>
Replace(Replace(Replace(Replace(Replace(
ValueStoreGet(“CompleteHTML”)
,“%id%”,dataResults.row.items.Count )
,“%checked%”, IIF( Left({%Complete},1)=“Y” ,“checked”,“”) )
,“%usid%”, “{_System.Rest.Usid}” )
,“%rootUrl%”, “{_System.Rest.URL}” )
,“%code%”, {%Code} )
