Retrieving a Record based on Two GUIDs

Jun 22, 2013 at 11:36 AM
We're trying to see if a record already exists. To do this we're using the retrieve function and we want to pass TWO GUID's to ensure we get the right one. This is what we have:
var contact; 
XrmSvcToolkit.retrieve({ 
    entityName: "Contact", 
  __  id: GUID_ONE, GUID_TWO, __
    async: false, 
    successCallback: function (result) { 
        contact = result; 
    }, 
    errorCallback: function (error) { 
       alert("Error");

    } 
});
Is that the correct way to do it? Moreover, how would one set a filter criteria, such as retrieve all contacts where the first name = Adventure, Telephone = 555-5322?
Jun 22, 2013 at 12:05 PM
What you are trying to do is (a) pass two GUIDS to retrieve a record, (b) create a filtered query with parameters which I don't think is possible right now with the XrmSvcToolkit. Try using the XRM service Toolkit by Jamie, I've done it myself with the Xrm Service Toolkit instead and implementation is quicker too.
Jun 22, 2013 at 12:51 PM
Thanks for the reply Michael. I will look into the XrmServiceToolkit but I would like to use this library instead mainly because it has been faster and formatted better. However it is possible to do what I have asked by using the retrieve multiple function, but I am not sure if I have formatted well. At the moment I get an Error, because I don't think my query is formatted well. here is the code:
                        XrmSvcToolkit.retrieveMultiple({ 
                        entityName: "contact", 
                        async: false, 
                        odataQuery: "?$filter=new_Client/Id eq + AccountGI, new_ConflictClient/Id eq AccountCGI",
                        successCallback: function (result) { 
                            //contacts = result; 
                            
                            alert("Sucess");
                        }, 
                        errorCallback: function (error) { 
                           alert("Error");
                    
                        } 
                    });
The line that I think is causing me problems is: odataQuery: "?$filter=new_Client/Id eq + AccountGI, new_ConflictClient/Id eq AccountCGI",

Still looking for suggestions.
Coordinator
Jun 24, 2013 at 1:25 AM
As per documentation, try something like this (AccountGI and AccountCGI are assumed to be variables set to GUIDs of corresponding records):
odataQuery: "?$filter=new_Client/Id eq (guid'" + AccountGI + "') and new_ConflictClient/Id eq (guid'" + AccountCGI + "')"
If you are after OR condition, simply replace 'and' with 'or'.
HTH
George
Coordinator
Jun 24, 2013 at 3:51 AM
@PhilipMorris, yes, using retrieveMultiple is the right path, since retrieve is designed to retrieve only one record at a time.

When you are uncertain about your query, your best friend is OData Query Designer. I believe George has already got you the right format.