<?xml encoding=”UTF-8″>By Daniel Du

In part 6, we transferred the DWG attachment to AutoCAD WS storage, in this post, we will try to open it in AutoCAD WS online editor.
In part 4, we introduced how to pass parameters between visual force page and apex controller, please pay attention to the code in bold:
<span class="kwrd"><font color="#000000"><</font></span><font color="#000000"><font><span class="html">script</span> <span class="attr">type</span><span class="kwrd">="text/javascript"</span><span class="kwrd">></span>
<strong><span class="kwrd">function</span> openInWS(url){
window.open(url);
}
</strong><span class="kwrd"></</span><span class="html">script</span></font><span class="kwrd"><font>></font></span></font>
<span class="kwrd"><font color="#000000"><</font></span><font color="#000000"><font><span class="html">apex:column</span> <span class="attr">id</span><span class="kwrd">="colOpenInAcadWS"</span>
<span class="attr">rendered</span><span class="kwrd">="{!CONTAINS(item.ContentType, 'application/x-dwg')}"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">p</span> <span class="attr">id</span><span class="kwrd">="{!count}.openInAcadWS"</span><span class="kwrd">></</span><span class="html">p</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">apex:commandLink</span> <span class="attr">action</span><span class="kwrd">="{!transferToWSStorage}"</span>
<span class="attr">title</span><span class="kwrd">="Open In AutoCAD WS"</span> <br> <span class="attr">id</span><span class="kwrd">="btnOpenInAutoCADWs"</span>
<span class="attr">value</span><span class="kwrd">="Open In AutoCAD WS"</span>
<span class="attr">styleClass</span><span class="kwrd">="btn"</span> <span class="attr">style</span><span class="kwrd">="text-decoration:none"</span>
<strong><span class="attr">oncomplete</span><span class="kwrd">="openInWS('{!openInAutocadWSUrl}');"</span></strong> <span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">apex:param</span> <span class="attr">name</span><span class="kwrd">="selectedAttachmentId"</span>
<span class="attr">value</span><span class="kwrd">="{!item.Id}"</span><span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">apex:commandLink</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">apex:pageBlock</span> <span class="attr">id</span><span class="kwrd">="hiddenBlock"</span> <span class="attr">rendered</span><span class="kwrd">="false"</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">apex:pageBlock</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">apex:column</span></font><span class="kwrd"><font>></font></span></font>
In controller:
//set openInAutocadWSUrl so that it can be |
A command link apex tag invokes an action of apex controller. In the controller, we transferred the DWG attachment to AutoCAD WS storage, and build the URL to open in WS online editor. Once the action is completed, a JavaScript function “oncomplete” will be invoked, we just use window.open() to launch the URL in a new window. We have already transferred the DWG to AutoCAD storage, now we are going to build the launching URL.
This is the implementation of getOpenDrawingURL, it returns the URL to open DWG files in AutoCAD WS online editor:
//===========Open drawing begin =============== |
I create a class OpenInWSHandler. Firstly we need to pass the username and password to AutoCAD WS authenticate URL to get the authentication token. after we get the token, we can use it to build the “AutoCAD-WS-Open-URL”. Here is the source code:
Public Class OpenInWSHandler { |
Since we are trying to access another remote web site https://www.autocadws.com/, we also need to to enable Salesforce to access remote site, please check Setup->Security->Remote site settings.
We are ready to give it a run, open the visual force page(please note we need to pass a case Id to list the attachments), and click the “Open In AutoCAD WS” button, a few seconds latter, a new window will launch AutoCAD WS online editor to open this DWG file.
In next post, I will introduce how to integer this visual force page to your case layout, so that you do not need to input the case id in URL manually.
Good luck and have fun!

Leave a Reply