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 do you get the HTML contents of a widget into the c.data object?

mikeszafranski
ServiceNow Employee
ServiceNow Employee

One of my team-mates created a very nice HTML report widget in Service Portal.       Now the client would like to save a PDF copy of the report.   I know we can render HTML fields as PDF but how do you get the HTML contents of a widget back to the server side for further processing and attaching to a record?

Thanks for the advice.     I'be been playing around with html2canvas with nor progress.

Mike

1 ACCEPTED SOLUTION

mikeszafranski
ServiceNow Employee
ServiceNow Employee

Answer my own question:



In the HTML:


we tag the div with an ID


<div id = "preview">



We also add a button:



    <button type="submit" ng-click="c.canvas()" class="btn btn-primary">Canvas</button>




In the client script a function that is called by the button:


c.canvas = function preview(){


  c.data.myHTML = document.getElementById('preview').innerHTML;


  c.server.update();


  }


View solution in original post

1 REPLY 1

mikeszafranski
ServiceNow Employee
ServiceNow Employee

Answer my own question:



In the HTML:


we tag the div with an ID


<div id = "preview">



We also add a button:



    <button type="submit" ng-click="c.canvas()" class="btn btn-primary">Canvas</button>




In the client script a function that is called by the button:


c.canvas = function preview(){


  c.data.myHTML = document.getElementById('preview').innerHTML;


  c.server.update();


  }