How can I host a plain HTML file on ServiceNow?

afranklin
Mega Contributor

Hi,

We'd like to serve plain vanilla HTML (or JSON, or other plain text) from the ServiceNow server with absolutely no ServiceNow specific markup being added. We'd like to do this for a number of reasons, including:

  • serving AngularJS templates
  • API stubs (for testing purposes)
  • Development scenarios where the Jelly overhead and boilerplate SN markup is not needed or otherwise gets in the way

The closest we've been able to come so far is attaching a text document to a knowledge base article, but this hack isn't suitable because the process is extremely cumbersome and the resulting url is unwieldily, difficult to predict and manage, and would force us to hard-code the sys id of the Knowledge article into our Angular code. Any thoughts?

13 REPLIES 13

ChrisBurks
Mega Sage

Hi Akil,



Not sure if you still have this issue, but I followed the instructions from Chris' first link and it worked for me!



Making a UI Page without using the framework page template



That worked for making Angular directive templates. Did it work for you? Should we mark that as correct answer here?



Cheers


vito4
Kilo Explorer

I have got this working via a custom processor.


First i created a processor of type 'script'.


I gave it a path of ajstemplate


I then put the following in the script field:


var template = g_request.getParameter('template');


var gr = new GlideRecord("content_block_static");


gr.addQuery("name", template);


gr.query();


if (gr.next()) {


  var html = gr.static_content.replace(/<!--[^>]*>\n?/g, '')


  g_processor.writeOutput('text/plain', html);


}


else{


  var gr = new GlideRecord("content_block_programmatic");


  gr.addQuery("name", template);


  gr.query();


  if (gr.next()) {


  var html = gr.programmatic_content.replace(/<!--[^>]*>\n?/g, '')


  g_processor.writeOutput('text/plain', html);


  }


  else {


  g_processor.writeOutput('text/plain', '');


  }


}



Now i can store pure html in a dynamic content css block, or a static html content block (However, the static content block in my instance removes custom html attributes like "ng-repeat" etc, so i mainly use dynamic content blocks.)


The trick is to make sure in the dynamic content blocks, you must remove the xml and jelly tags though.



The processor will also remove any html comments, so you may comment your content blocks as heavily as you like, and it will not be output at all.



And in the url for my angular directives, i can use:


//<instance name>.service-now.com/ajstemplate.do?template=<Name_Of_My_Content_Block>



Hope this helps someone...


I did the same thing.