I am using an IFD CRM2011 environment and I am following this MSDN example to query the ODATA endpoint to populate a dropdown menu within an IFrame.
Here is the code that populates the drop down list:
function GetQuestionSetList() {
var query = '/Mhc_questionsetverSet?' +
'$select=Mhc_name,Mhc_questionsetverId&$filter=statecode/Value eq 0';
SDK.RestEndpointPaging
.RetrieveRecords(query, ProcessReturnedQuestionSetVersions);
}
function ProcessReturnedQuestionSetVersions(retrievedQuestionSets) {
for (var i = 0; i < retrievedQuestionSets.length; i++) {
var questionSet = retrievedQuestionSets[i];
var value = questionSet.Mhc_questionsetverId;
var name = questionSet.Mhc_name;
//add option to select list
$('#selectQuestionSetVersion').append($('<option>')
.attr('value', value)
.text(name));
}
}
After the SDK.RestEndpointPaging.RetrieveRecords(query, ProcessReturnedQuestionSetVersions); line executes I am prompted with this dialog:

At this point I can either enter my credentials or press cancel and the dropdown is populated. In the developer tools I notice this error in both cases:
SCRIPT5022: Exception thrown and not caught
mhc_json2.js, line 484 character 13
// If the text is not JSON parseable, then a SyntaxError is thrown.
throw new SyntaxError('JSON.parse'); //line 484
};
}
}());
I can’t figure out why this dialog is appearing or why this error is being thrown.
After posting this, I just happened to check fiddler and discovered the problem. There are two calls to
RetrieveRecordsin my situation. The first call returns status 200 (success) but the second returns 401.Here are the two calls:
In the second call the server + odata endpoint are concatenated twice. The
RetrieveRecordsCallbackfunction is supposed to strip the server and endpoint url if the__nextparameter is found as seen here:The
SDK.RestEndpointPaging.GetODataPath()is appending an extra/between the server and endpoint parts of the url, but when the new filter parameter is returned that extra/has been stripped so the.replacefunction fails to replace the path and it gets appended a second time.The fix was trivial. Just change the
SDK.RestEndpointPaging.GetODataPath()function to this: