Skip to content

Instantly share code, notes, and snippets.

@NielsGregers
Created October 12, 2016 15:32
Show Gist options
  • Save NielsGregers/794a27f7979f77613217a869db0c1ce5 to your computer and use it in GitHub Desktop.
Save NielsGregers/794a27f7979f77613217a869db0c1ce5 to your computer and use it in GitHub Desktop.
Send Fax based on coping a document and converting it to PDF
<h2 class="animated rubberband">Sending a fax</h2>
<h3>Technical flow</h3>
<ul>
<li>A template is copied to the folder "/fax/10-new" and named [timestamp]-[templatename].docx</li>
<li>Properties are set on the document [timestamp]-[templatename].docx</li>
<li>When the column "Fax to number" is filled out, the document will automatically be moved to the folder "/fax/20-processing", and a PDF conversion is requested</li>
<li>A processs is monitoring the folder "/fax/20-processing", and a when a matching PDF file is found, the .DOCX and .PDF files are moved to the folder "/fax/90-processed"</li>
</ul>
<hr/>
<button class="animated bounce" onclick="sendFax('master1.docx')">Click here to create a new document</button>
<div id="faxstatus"></div>
</hr>
<h2>Configuration</h2>
<ul>
<li>Place your templates in the folder "fax/95-templates"</li>
</ul>
function sendFax(master){
var name= new Date().getTime();;
name+="-"+(master.substring(0,master.indexOf('.')))
var settings = {
"async": true,
"crossDomain": true,
"url": "http://sharepoint.cartoons/v1/document/copy",
"method": "POST",
"headers": {
"content-type": "application/json",
"cache-control": "no-cache"
},
"processData": false,
"data": "{\r\n \"fromServerRelativePath\": \"/sites/cs-dk-front/v2/confidential/Documents/fax/95-templates/"+master+"\",\r\n \"toServerRelativePath\": \"/sites/cs-dk-front/v2/confidential/Documents/fax/10-new/"+name+".docx\",\r\n \"webUrl\": \"http://share/sites/cs-dk-front/v2/confidential\"\r\n}"
}
$("#faxstatus").html("Creating document")
$.ajax(settings).done(function (response) {
if (response.id){
var link = "http://share/sites/cs-dk-front/v2/confidential/Documents/Forms/EditForm.aspx?ID="+response.id+"&Source=http%3A%2F%2Fshare%2Fsites%2Fcs%2Ddk%2Dfront%2Fv2%2Fconfidential"
$("#faxstatus").html("Operation completed - <a href='"+link+"' target='_blank'>click to open document properties</a><br/>" + link)
window.location = link
}else
{
$("#faxstatus").html("Error:" + response)
}
console.log(response);
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment