Search This Blog

Monday, June 2, 2014

Retrieve Record using Odata query filter with GUID of Record



var GroupId = Xrm.Page.data.entity.getId();
var _query = "?$filter=new_GroupId/Id eq (Guid'"+ GroupId +"')";
var obj = RecRetrieveMultiple(_query, 'new_student');

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;
}

Thursday, February 27, 2014

Add Custom help Document for CRM 2011 and CRM 2013



Steps:


1.Make an HTML web resource in CRM.  

      2. Make a button using ribbon editor in CRM. And in action give URL of web resource so that when you click on button it will open the web resource. 




      
           3. Now we want to get object type code of an entity on which button is added. Get object type code from URL using javascript. This is the full code of web resource it also contains javascript code to get object type code from URL and to open selected div when button press from different entities(to make help document with different materail to show.) Only add your html in div and enjoy.



    <html>

    <head>

                 <script src="ClientGlobalContext.js.aspx"></script>

                <script type="text/javascript" src="new_jquery_1.4.1.min.js"></script>

                <script type="text/javascript">

   function getParam ( sname )//function to get url

   {

                var params = location.search.substr(location.search.indexOf("?")+1);

                 var sval = "";

                params = params.split("&");

                // split param and value into individual pieces

                for (var i=0; i<params.length; i++)

                {

                                 temp = params[i].split("=");

                                 if ( [temp[0]] == sname ) { sval = temp[1]; }

                 }

                return sval;

   }
    function foo() // function to open Web resource on specific entities 
          {       

                  var bar =  getParam("type");

                 if(bar=="1" )

                 {

                                 document.getElementById('cont').style.display = "none";

                 }

                                                 

                 else if (bar=="2" )

                 {

                                 document.getElementById('ac1').style.display = "none";

                 } 

          }

   </script>

   </head>

                <body onload="foo()">

                                <div id="ac1" style="display:block" >

                                                <h2>Create or edit an accounts</h2>

                                                <h4>Applies To</h4>

                                                <ul>

                                                                <li>Microsoft Dynamics CRM Online</li>

                                                                <li>Microsoft Dynamics CRM 2013</li>

                                                                <li>CRM for web browsers</li>

                                                                <li>CRM for Outlook</li>

                                                </ul> 

                                </div>

                                 <div id="cont" style="display:block">

                                                 <h2>Create or edit an contact</h2>

                                                 <h4>Applies To contact</h4>

                                                    <ul>

                                                                <li>Microsoft Dynamics CRM Online</li>

                                                                <li>Microsoft Dynamics CRM 2013</li>

                                                                <li>CRM for web browsers</li>

                                                                <li>CRM for Outlook</li>

                                                </ul>

                                 </div>

                </body>
</html>