Sales Force

From DevWiki

Jump to: navigation, search

The Volusion API can be integrated with SalesForce web applications through the Apex Developer Network (ADN) http://www.salesforce.com/developer/. Simply create an ADN account and follow the steps below.


Step 1: Building an S-Control

Login to the Apex Developer Network https://www.salesforce.com/login.jsp and go to Setup which is located at top-middle of the page. Then at the App Setup section located at the left navigation, Go to S-Controls under Build. Click on the New Custom S-Control button and save the content below:


<html>
  <head>
    <title>New Orders</title>
    <style>
      body {
        background-repeat: no-repeat;
        background-color: "#FFFFFF";
        border: 0px solid transparent;
        margin: 0px;
      }
    </style>
    <style type="text/css">
      .regular {
        font-family: arial;
        font-size: 12px;
        color: #000000;
        background-color: "#FFFFFF";
      }
    </style>
    <script type="text/javascript" src="/js/functions.js"></script> 
    <script src="/soap/ajax/10.0/connection.js"></script> 
    <script type="text/javascript">
      var chkConn;                
      var s_url = "";
      var s_email = "";
      var s_password = "";
      var s_interval = "";

      function load_gadget() {
        if (isNaN(s_interval) == true || s_interval == "") {s_interval = 5;}	
        load_settings();
        chkConn = setInterval(download_orders, 5000);
      }
		
      function download_orders() {
        var edi_param = "Login=" + s_email + "&EncryptedPassword=" + s_password + "&EDI_Name=Generic\\Orders&SELECT_Columns=o.OrderID,o.OrderStatus,od.TotalPrice&WHERE_Column=o.OrderStatus&WHERE_Value=New";
        var edi_url = "http://" + s_url + "/net/WebService.aspx?" + edi_param;
        var xmlhttp;
        var edi_response = "";
				
        sforce.connection.remoteFunction( {
          url : edi_url,
          mimeType: "text/plain",
          requestHeaders: {"Content-Type":"application/x-www-form-urlencoded","Content-Length":edi_param.length},
          method: "POST",
          requestData: edi_param,
          async: true,
          onFailure : display_failure,
          onSuccess : display_orders
        });
      }
			
      function display_failure() {
        if (s_url == "" || s_email == "" || s_password == "") {
          content_area.innerHTML = "Check settings";
        } else {
          content_area.innerHTML = "Unable to connect";
        }
      }

      function display_orders(edi_response) {
        var xml_edi;
        var xml_order;
        var xml_order_detail;
        var node_orders;
        var node_order_details;
        var i = 0, j = 0;
        var order_id = "";
        var total_price = 0;
        var order_price = 0.0;
        var html_orders = "";
        var order_count = 0;

        	
        html_orders = html_orders + "<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=#000000><table cellpadding=3 cellspacing=1 width=150  border=0>";
        html_orders = html_orders + "<tr><td bgcolor=#FFFFFF><font style=\"color:#000000;font-family:arial;font-size:12px;\">Order ID</font></td><td align=right bgcolor=#FFFFFF><font style=\"color:#000000;font-family:arial;font-size:12px;\">Total</font></td></tr>";
          		

        try {
          xml_edi = new ActiveXObject("MSXML2.DOMDocument");
          xml_edi.loadXML(edi_response);
          node_orders = xml_edi.getElementsByTagName("Orders");
          xml_order = new ActiveXObject("MSXML2.DOMDocument");
          xml_order_detail = new ActiveXObject("MSXML2.DOMDocument");
		
          if (node_orders.length > 0) {
            for (i = node_orders.length - 1; i > -1; i--) {
              xml_order.loadXML(node_orders.item(i).xml); 
              order_id = get_node_text(xml_order, "Orders/OrderID");
              order_price = 0.0;
              node_order_details = xml_order.getElementsByTagName("Orders/OrderDetails");
              if (node_order_details.length > 0) {
                for (j = 0; j < node_order_details.length; j++) {
                  xml_order_detail.loadXML(node_order_details.item(j).xml);
                  total_price = get_node_text(xml_order_detail, "OrderDetails/TotalPrice");
                  if (isNaN(total_price) == false) {
                    order_price = parseFloat(order_price) + parseFloat(total_price);
                  }	
                }
              }
              html_orders = html_orders + "<tr><td bgcolor=#FFFFFF>" + order_id + "</td><td align=right bgcolor=#FFFFFF>$" + (Math.round(order_price * 100) / 100).toFixed(2) + "</td></tr>";
              order_count++;
              if (order_count > 10) {break;}
            }
          }
        } catch(err) {
          //error parsing xml
        } 

        html_orders = html_orders + "</table></td></tr></table>";
        content_area.innerHTML = html_orders;
      }

      function get_node_text(xml_doc, node_name) {
        var current_node;
        var node_text;

        current_node = xml_doc.getElementsByTagName(node_name);
        if (current_node.length > 0) {node_text = current_node.item(0).text;}
        return node_text;	
      }

      function load_settings() {
        try {
          s_url = "YourUrl";   
          s_email = "YourEmail";   
          s_password = "YourPassword";   
          s_interval = 30;   
        } catch(err) {
        }
      }
    </script>
  </head>

 <body onLoad="load_gadget();">
   <table border=0 cellpadding=0 cellspacing=0 style="margin-top:2px;">
     <tr>
       <td>
         <span id="content_area"><font style="color:#000000;font-family:calibri;font-size:12px;\">Loading...</font></span>
       </td>
     </tr>
   </table>
 </body>
 
</html>

Step 2: Building Apps

Go to Setup, and at the left navigation, click Build > Apps. In the introduction page, click the continue button. Create a custom app by clicking the New button. Enter a label and description and click next. Insert an image and click next. Add the custom Tab to the custom app click next. Then assign the profile permissions to the app and save.

Step 3: Building Tabs

In order to build a Tab for the S-Control, go to Tabs under App Setup > Build. Click the New button, select the tab layout and click next. Choose Custom S-Control for the tab type, and enter the tab properties, enter a description and click next. Select the Custom S-Control for the for tab and click next. Assign the tab visibility to profiles and click next. Finally, include the to existing custom apps.

Navigation