Problem with Rest RetrieveMultiple

Nov 29, 2013 at 6:14 PM
Edited Nov 29, 2013 at 6:21 PM
Any ideas what I am doing wrong? I have tried multiple permutations of the filter and still can't get it working. Thanks in advance.

var contractId = Xrm.Page.getAttribute("jov_contractid").getValue()[0].id;
    XrmServiceToolkit.Rest.RetrieveMultiple(
        "jov_period",
        "$filter=jov_Contractid/Id eq guid'" + contractId + "' and statuscode eq 1",
        function (results) {
                return results;
        },
        // ReSharper disable once UnusedParameter
        function(error) {
        },
        function onComplete() {
        },
        false);
I've tried

"$filter=jov_Contractid eq " + contractId + " and statuscode eq 1",
"$filter=jov_Contractid eq ''" + contractId + "' and statuscode eq 1",
"$filter=jov_contractid/Id eq guid'" + contractId + "' and statuscode eq 1"
amongst others with no luck.
Nov 29, 2013 at 7:16 PM
I've made some headway. The correct filter is:

$filter=jov_Contractid/Id eq guid'41AFD426-B658-E311-9864-00155DA8A105' and statuscode/Value eq 1

This works in a RestClient (Firefox plugin) but still returns "undefined" using the RetrieveMultiple method.
Nov 29, 2013 at 7:46 PM
Edited Nov 29, 2013 at 7:46 PM
I should have titled this "One man's quest to enlightenment...."

this works
    var contractId = Xrm.Page.getAttribute("jov_contractid").getValue()[0].id;
    var dumdum = null;    
    XrmServiceToolkit.Rest.RetrieveMultiple(
        "jov_periodSet",
        "$filter=jov_Contractid/Id eq guid'" + contractId + "' and statuscode/Value eq 1",
        function (results) {
                dumdum = results;
        },
        // ReSharper disable once UnusedParameter
        function(error) {
        },
        function onComplete() {
        },
        false);

    return dumdum;
I hope this saves someone else some time and embarrassment. :-)
Coordinator
Nov 30, 2013 at 8:00 PM
Hi There.

Glad that you have worked it out yourself.

Building Rest Endpoint query is indeed an effort to be made in terms of CRM development in JavaScript :)

Regards,
Jaimie
Dec 9, 2013 at 1:23 PM
Yes, saving results of an retrieve can be really trick in some parts, especially with async on :) You could also call a function in the success with the results as parameter if applicable.