locked
Call to SDK.Rest is not working from within HTML web resource RRS feed

  • Question

  • Hi,

    I am trying to make a call to SDK.Rest from a HTML web resource. When I had this code in the form javascript, it worked, and I could see the values being retrieved. However, as I need to populate some list boxes in the web resource with this data, I had to move the code to the web resource. I have put in some alerts to see how far it is getting, and it is only getting as far as just before the call to SDK.Rest, but no further. I have no idea what I have done wrong, and have tried a LOT of different things. I've been googling it for ages.

    Could someone please take a look and see if you can spot what it wrong? Thanks.

    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
      body
      {
       font-family: Segoe UI, Tahoma, Arial;
       background-color: white;
      }
      tbody
      {
       background-color: white;
      }
      th
      {
       background-color: black;
       color: White;
      }
     </style>
    <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>-->
     <script src="ClientGlobalContext.js.aspx"></script>
     <!--<script src="Scripts/SDK.REST.js" type="text/javascript"></script>-->
    <script type="text/javascript" src="SDK.REST.js"></script>
    <script type="text/javascript">
    
    document.onreadystatechange = function () {
    	 if (document.readyState == "complete") {
    		RetrieveAvailableAccessories();	
    	 }
     }
     
      function RetrieveAvailableAccessories()
    {	alert("In RetrieveAvailableAccessories");
    	// Get opp type	
    	var oppType = window.parent.Xrm.Page.getAttribute("co_oppType").getValue();
    	alert("oppType: " + oppType);
    	var prodTypeCodeValue;
    	var options;
    	if (oppType == 100000000) // New 
    	{
    		options = "$select=ProductId,Name,co_IsReserved,ProductTypeCode&$filter=ProductTypeCode/Value eq 3";
    	}
    	else if (oppType == 100000001) // Old
    	{
    		options = "$select=ProductId,Name,co_IsReserved,ProductTypeCode&$filter=co_IsReserved eq false and ProductTypeCode/Value eq 4";
    	}
    alert("options: " + options);	// Displayed
    	SDK.REST.retrieveMultipleRecords("Product", options, retrieveProductsCallBack, errorCallBack, productsRetrieveComplete);
    alert("After call to retrieveMultiple");	// Not displayed
    }
    
    function retrieveProductsCallBack(retrievedProducts) {
    alert("In retrieveProductsCallBack"); // Not displayed
    var outputString = "";
    outputString = "Name\t\t\tIs Reserved\t\t\tProduct Type\n";
    outputString = outputString + "--------------------------------------------------\n";
    for (var i = 0; i < retrievedProducts.length; i++) {
    outputString = outputString + retrievedProducts[i].ProductId + retrievedProducts[i].Name + " \t " + retrievedProducts[i].str_IsReserved + " \t " + retrievedProducts[i].ProductTypeCode.Value + "\n";
    }
    alert(outputString); // Not displayed
    }
    
    function errorCallBack(error) {
    alert(error.message);
    }
    
    function productsRetrieveComplete() {
    	alert("Products retrieve complete"); // Not displayed
    }
     
    </script>
    </head>
    <body>
    
    <div>
    <table width=100%>
     <tr>
        <th>Available</th>
    	<th></th>
        <th>Chosen</th>
      </tr>
    <tr>
    <td width=40%>    
        <select id="list1" multiple="multiple" rows=2 style="width: 100%; height: 100%;">
            <option value=1>Option 1</option>
            <option value=2>Option 2</option>
            <option value=3>Option 3</option>
            <option value=4>Option 4</option>
        </select>
        <br/>
    </td>
    <td width="20%">
    <table>
    <tr>
        <td width="100%" align="center"><input id="button1" type="button" value=">" /></td>
    </tr>
    <tr>
    	<td width="100%" align="center"><input id="button2" type="button" value="<" /></td>
    </tr>
    </table>
    </td>
    <td width="40%">    
        <select id="list2" multiple="multiple" rows=2 style="width: 100%; height: 100%;">        
        </select>
        <br/>
    </td>
    </tr>
    </table>
    </div>
    
    </body>
    </html>
    

    Wednesday, August 30, 2017 4:11 PM

Answers

  • Hi,

    Thanks for your reply. This issue was slightly different to my other one, so I opened another question. I have actually just fixed this now - I had the name of one of the referenced javascript files slightly wrong.

    • Marked as answer by MOTO1978 Wednesday, August 30, 2017 4:23 PM
    Wednesday, August 30, 2017 4:22 PM

All replies

  • Hello,

    1. You can use your browser to troubleshoot issues in your code.

    2. It is good to close threads you created before like this one.


    Dynamics CRM/Business Solutions MVP
    Read My blog


    Wednesday, August 30, 2017 4:20 PM
    Moderator
  • Hi,

    Thanks for your reply. This issue was slightly different to my other one, so I opened another question. I have actually just fixed this now - I had the name of one of the referenced javascript files slightly wrong.

    • Marked as answer by MOTO1978 Wednesday, August 30, 2017 4:23 PM
    Wednesday, August 30, 2017 4:22 PM