Search This Blog

Monday, June 2, 2014

Retrieve Multiple Records Using Odata and Using Soap library


First Download xrmsvctoolkit library from here

Case: Apply code on account form and get account id and use this account id to check how many contacts are against that account id in retrieve multiple using OData.

function get_call()
{             
                var GUIDvalue = Xrm.Page.data.entity.getId();
                //alert(GUIDvalue);
                var lookupObject = Xrm.Page.getAttribute("primarycontactid");
                var lookUpObjectValue = lookupObject.getValue();
                var query = "?$filter=ParentCustomerId/Id eq (Guid'"+GUIDvalue+"')";
                var obj1 = get_Multiple(query,"Contact");
                //var obj1 = get_Multiple(lookUpObjectValue[0].id,"Contact");
                if(obj1==null)
                {
                                alert("I am null");
                }
                else
                {
                                alert(obj1.FullName+"currency : "+obj1.TransactionCurrencyId.type+obj1.TransactionCurrencyId.Name);
                }
                //for (var indx = 0; indx < obj1.length; indx++)
                //{
                                //alert("Name – " + obj1[indx].FullName + " "+"mobile  no: "+obj1.MobilePhone);
                //}
}
function get_Multiple(_query,_entitynames)
{

    XrmSvcToolkit.retrieveMultiple({
        entityName: _entitynames,
        async: false,
        odataQuery: _query,//"?$filter=FirstName eq 'Jim'  and EMailAddress1 eq 'someone@example.com' ",
        successCallback: function (result) {
            contacts = result;
        },
        errorCallback: function (error) {
           alert("Error");
        }
    });
                alert(contacts.length);
    var contact = contacts[0];
                return contact;
}

1 comment: