This is a slightly different approach that I recently discovered, that
kinda sorta does the same thing.

IF you have an HTML document in a char field, AND IF your intention is to
render that HTML for the user (for instance, by using a set-fields action
to place the HTML document in an iFrame (oops 'View Field' in remedy-land)
... AND IF, what your users REALLY want is just a way to export that HTML
document into something they can edit and/or save (for instance Word,
Excel, Txt, etc) ...

Well then, I have a pretty darn cool trick for you:

   1. Include the jQuery javascript library in your HTML document header

   the Mid-Tier itself actually already has a copy of this library that it
   uses for it's own purposes. Unfortunately, I've not figured out any decent
   way of creating a static link to it for the purposes of constructing an
   HTML include, it's just too much of a mess, and Mid-tier doesn't seem to
   want to serve files anyhow, unless you go and hack around in the tomcat
   config. For that reason, I usually just include it straight from google
   (like pretty much everyone else on the internet):


* <script
   src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
   <https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js>"></script>
   *
   2. Include the FileSaver jQuery plugin

   It is available here
*https://github.com/eligrey/FileSaver.js
   <https://github.com/eligrey/FileSaver.js> *Unfortunately, there's no
   public CDN the likes of which google puts out for jQuery, however, there's
   a brute force way around that. Just download the js file, remove the line
   breaks, and insert it into your HTML document, like so:



*<script type="text/javascript">var saveAs=saveAs||"undefined"!=typeof
   
navigator&&navigator.msSaveOrOpenBlob&&navigator.msSaveOrOpenBlob.bind(navigator)||function(e){"use
   strict";if("undefined"==typeof navigator||!/MSIE
   [1-9]\./.test(navigator.userAgent)){var t=e.document,n=function(){return
   e.URL||e.webkitURL||e},o=t.createElementNS("http://www.w3.org/1999/xhtml
   <http://www.w3.org/1999/xhtml>","a"),r="download"in o,i=function(n){var
   
o=t.createEvent("MouseEvents");o.initMouseEvent("click",!0,!1,e,0,0,0,0,0,!1,!1,!1,!1,0,null),n.dispatchEvent(o)},a=e.webkitRequestFileSystem,c=e.requestFileSystem||a||e.mozRequestFileSystem,s=function(t){(e.setImmediate||e.setTimeout)(function(){throw
   t},0)},u="application/octet-stream",f=0,d=500,l=function(t){var
   o=function(){"string"==typeof
   
t?n().revokeObjectURL(t):t.remove()};e.chrome?o():setTimeout(o,d)},v=function(e,t,n){t=[].concat(t);for(var
   o=t.length;o--;){var r=e["on"+t[o]];if("function"==typeof
   r)try{r.call(e,n||e)}catch(i){s(i)}}},p=function(t,s){var
   d,p,w,y=this,m=t.type,S=!1,h=function(){v(y,"writestart progress write
   writeend".split("
   
"))},O=function(){if((S||!d)&&(d=n().createObjectURL(t)),p)p.location.href=d;else{var
   o=e.open(d,"_blank");void 0==o&&"undefined"!=typeof
   
safari&&(e.location.href=d)}y.readyState=y.DONE,h(),l(d)},b=function(e){return
   function(){return y.readyState!==y.DONE?e.apply(this,arguments):void
   0}},g={create:!0,exclusive:!1};return
   
y.readyState=y.INIT,s||(s="download"),r?(d=n().createObjectURL(t),o.href=d,o.download=s,i(o),y.readyState=y.DONE,h(),void
   
l(d)):(/^\s*(?:text\/(?:plain|xml)|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(t.type)&&(t=new
   
Blob(["",t],{type:t.type})),e.chrome&&m&&m!==u&&(w=t.slice||t.webkitSlice,t=w.call(t,0,t.size,u),S=!0),a&&"download"!==s&&(s+=".download"),(m===u||a)&&(p=e),c?(f+=t.size,void
   c(e.TEMPORARY,f,b(function(e){e.root.getDirectory("saved",g,b(function(e){var
   
n=function(){e.getFile(s,g,b(function(e){e.createWriter(b(function(n){n.onwriteend=function(t){p.location.href=e.toURL(),y.readyState=y.DONE,v(y,"writeend",t),l(e)},n.onerror=function(){var
   e=n.error;e.code!==e.ABORT_ERR&&O()},"writestart progress write
   abort".split("
   
").forEach(function(e){n["on"+e]=y["on"+e]}),n.write(t),y.abort=function(){n.abort(),y.readyState=y.DONE},y.readyState=y.WRITING}),O)}),O)};e.getFile(s,{create:!1},b(function(e){e.remove(),n()}),b(function(e){e.code===e.NOT_FOUND_ERR?n():O()}))}),O)}),O)):void
   O())},w=p.prototype,y=function(e,t){return new p(e,t)};return
   w.abort=function(){var
   
e=this;e.readyState=e.DONE,v(e,"abort")},w.readyState=w.INIT=0,w.WRITING=1,w.DONE=2,w.error=w.onwritestart=w.onprogress=w.onwrite=w.onabort=w.onerror=w.onwriteend=null,y}}("undefined"!=typeof
   self&&self||"undefined"!=typeof
   window&&window||this.content);"undefined"!=typeof
   module&&module.exports?module.exports.saveAs=saveAs:"undefined"!=typeof
   define&&null!==define&&null!=define.amd&&define([],function(){return
   saveAs});</script> *
   3. Not necessarily required, but my users specifically wanted Microsoft
   Word export, so this handy library is what I used:

*https://github.com/markswindoll/jQuery-Word-Export
   <https://github.com/markswindoll/jQuery-Word-Export> *
   again, I just downloaded the js file, stripped the line breaks and
   manually inserted it into my HTML document as such:


*<script type="text/javascript">if (typeof jQuery !== "undefined" && typeof
   saveAs !== "undefined") { (function($) { $.fn.wordExport =
   function(fileName) { fileName = typeof fileName !== 'undefined' ? fileName
   : "jQuery-Word-Export"; var static = { mhtml: { top: "Mime-Version:
   1.0\nContent-Base: " + location.href + "\nContent-Type: Multipart/related;
   
boundary=\"NEXT.ITEM-BOUNDARY\";type=\"text/html\"\n\n--NEXT.ITEM-BOUNDARY\nContent-Type:
   text/html; charset=\"utf-8\"\nContent-Location: " + location.href +
   "\n\n<!DOCTYPE html>\n<html>\n_html_</html>", head: "<head>\n<meta
   http-equiv=\"Content-Type\" content=\"text/html;
   charset=utf-8\">\n<style>\n_styles_\n</style>\n</head>\n", body:
   "<body>_body_</body>" } }; var options = { maxWidth: 624 }; var markup =
   $(this).clone(); markup.each(function() { var self = $(this); if (self.is
   <http://self.is>(':hidden')) self.remove(); }); var images = Array(); var
   img = markup.find('img'); for (var i = 0; i < img.length; i++) { var w =
   Math.min(img[i].width, options.maxWidth); var h = img[i].height * (w /
   img[i].width); $('<canvas>').attr("id", "jQuery-Word-export_img_" +
   i).width(w).height(h).insertAfter(img[i]); var canvas =
   document.getElementById("jQuery-Word-export_img_" + i); canvas.width = w;
   canvas.height = h; var context = canvas.getContext('2d');
   context.drawImage(img[i], 0, 0, w, h); var uri = canvas.toDataURL();
   $(img[i]).attr("src", img[i].src); img[i].width = w; img[i].height = h;
   images[i] = { type: uri.substring(uri.indexOf(":") + 1, uri.indexOf(";")),
   encoding: uri.substring(uri.indexOf(";") + 1, uri.indexOf(",")), location:
   $(img[i]).attr("src"), data: uri.substring(uri.indexOf(",") + 1) };
   canvas.parentNode.removeChild(canvas); } var mhtmlBottom = "\n"; for (var i
   = 0; i < images.length; i++) { mhtmlBottom += "--NEXT.ITEM-BOUNDARY\n";
   mhtmlBottom += "Content-Location: " + images[i].contentLocation + "\n";
   mhtmlBottom += "Content-Type: " + images[i].contentType + "\n"; mhtmlBottom
   += "Content-Transfer-Encoding: " + images[i].contentEncoding + "\n\n";
   mhtmlBottom += images[i].contentData + "\n\n"; } mhtmlBottom +=
   "--NEXT.ITEM-BOUNDARY--"; var styles = ""; var fileContent =
   static.mhtml.top.replace("_html_", static.mhtml.head.replace("_styles_",
   styles) + static.mhtml.body.replace("_body_", markup.html())) +
   mhtmlBottom; var blob = new Blob([fileContent], { type:
   "application/msword;charset=utf-8" }); saveAs(blob, fileName + ".doc"); };
   })(jQuery); } else { if (typeof jQuery === "undefined") {
   console.error("jQuery Word Export: missing dependency (jQuery)");  } if
   (typeof saveAs === "undefined") { console.error("jQuery Word Export:
   missing dependency (FileSaver.js)");};}</script> *
   4. Create a link somewhere in your HTML document ... this is the link
   the user clicks to download the HTML document as a word document (CSS style
   it like a remedy button if you're feeling cheeky)
   Here's the link I put in my document:

   *<a href="javascript:void(0);" class="button word-export">Export as Word
   Document</a>*

   *note:* I put the link in the "word-export" class. That's important in a
   second

   5. Somewhere in the header of your document, insert the standard jQuery
   document.ready() function, and and insert the hook for your WordExport link:








*<script type="text/javascript">     $(document).ready(function() {
   // bind click to the word-export thang
   $("a.word-export").click(function(event) {
   $("#page-content").wordExport();         });     }); </script>*

   6. ... and this is slick as all hell ... tell wordExport.js which *part*
   of the document you'd like to export.

   Note this part of the function from step #5:
   *$("#page-content").wordExport();*
   That's basically telling jQuery: *"export the HTML element with an id of
   'page-content' as a word document". *So, basically find the part of the
   document you want to let the user download and name it "page-content" (or
   you know whatever ... just make sure your name matches what you state in
   the function). So in my case, it was just one big old:



*<div id="page-content">    <!-- literally everything in the document -->
   </div>*


boom ... done!
Users load up a record on my form, an active link  fires off and populates
an HTML template in AR System Resource Definitions, which gets placed in a
view field, and there's a link right there to download it as a word
document, no additional monkey business required!

Now ... why in the heck doesn't BMC just do this to generate print views
instead of monkeying around with BIRT??
I know the above looks like a lot, but believe me ... it's truly dead
simple, especially in comparison to dorking around with BIRT.

-Andy




On Jun 25, 2015 9:39 AM, "Jeff Lockemy" <[email protected]> wrote:

> Good Morning,
>
> I am looking to see if anyone has done something like this before and what
> method they may have used.
>
> I have a Remedy character field that contains a large amount of HTML text.
> I want to create a text file that contains the contents of that character
> field, name it "RequestID.html", and then place it into a Remedy attachment
> field.  We have tried a few things but neither is clean or has been without
> issues:
>
> - Build the file using DOS command within a filter Run Process (ECHO to a
> file)
> - Build the file using a filter Notify mechanism of Other (then rename the
> resulting .ARN notification file and attach it)
>
> Any other ideas or suggestions on how we might accomplish this is
> appreciated.
>
> Best regards,
> Jeff
>
>
> _______________________________________________________________________________
> UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
> "Where the Answers Are, and have been for 20 years"
>

_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org
"Where the Answers Are, and have been for 20 years"

Reply via email to