Wednesday, January 17, 2018

Microsoft Dynamics 365 v9.0 latest feature – Show Progress Indicator

In latest release of Dynamics 365 i.e. v9.0 MS has introduces many new features to enhance the user experience, Progress indicator is one of them.
Many times we need to write client side javascript code which take some time to execute due to many reasons (further server side code running etc). In such case, in earlier version user were not able to know that if anything is happening in background and  user needed to wait for next response from crm system.
Now in this release, MS has introduced progress indicator which is can be called as showProgressIndicator function of Xrm.Utility. namespace.
It’s take a text string as parameter to display on the progress indicator.
We have created an example test case of it’s use in which can be utilize in more relevant cases like while calling any function from ribbon button etc to show message to user.
Here we are loading the mobile no of primary contact of an account and showing it in an alert message and during the period we want user to be informed that system is loading it:

function getPrimaryContactMobile()
{
 Xrm.Utility.showProgressIndicator("Loading mobile no of primary contact..");
 setTimeout(delayedLoadPrimaryContactDetails, 3000);
}

function delayedLoadPrimaryContactDetails()
{
 var contact = Xrm.Page.getAttribute("primarycontactid").getValuentact == null){
 Xrm.Utility.closeProgressIndicator();
 return;
 }
 Xrm.WebApi.retrieveRecord("contact", contact[0].id, "$select=mobilephone")
 .then(function(result) {
 var mobileno = result["mobilephone"];
 Xrm.Utility.closeProgressIndicator(); //To close the progress indicator
 alert("Mobile no of primary conatct  : " + mobileno);
 })
 .fail(function(error) {
 Xrm.Utility.closeProgressIndicator();
 var message = error.message;
 alert("Error: "+message);
 });

1

I’m sure it can be useful in more complex scenarios.
Hope it would be helpful.

Thursday, January 11, 2018

CRUD Operation using Xrm.WebAPI In Dynamics 365-CRM

With Microsoft releasing Dynamics 365 update 9.0, now, we have a new library to implement WebAPI methods using Xrm.WebApi. Instead of writing the complete request, now we can just use direct the CRUD methods from the Web API.


Xrm.WebApi has two properties to use for the Online and the Offline client respectively. In this article, we are going to implement a sample HTML web resource using Xrm.WebApi for the online client.

Now, to create an entity record, we can simply call Xrm.WebApi Create method using the following parameters.





    <script>


        function createAccount() {

            // collect account data

            var data = {

                "name": document.getElementById("txtname").value,

                "address1_city": document.getElementById("txtcity").value,

                "telephone1": document.getElementById("txtphone").value,

                "numberofemployees": document.getElementById("txttotalemployees").value,

                "websiteurl": document.getElementById("txtwebsite").value


            }

            // create account record

            parent.Xrm.WebApi.createRecord("account", data).then(

                function success(result) {

                    document.getElementById("txtaccountid").value = result.id;

                    alert("Account Created !!");

                },

                function (error) {

                    alert(error.message);

                }

            );

        }

        function updateAccount() {

            // collect account data

            var data = {

                "name": document.getElementById("txtname").value,

                "address1_city": document.getElementById("txtcity").value,

                "telephone1": document.getElementById("txtphone").value,

                "numberofemployees": document.getElementById("txttotalemployees").value,

                "websiteurl": document.getElementById("txtwebsite").value


            }

            //get account id

            var accountId = document.getElementById("txtaccountid").value;


            // update account record

            parent.Xrm.WebApi.updateRecord("account", accountId, data).then(

                function success(result) {

                    alert("Account Record Updated");


                },

                function (error) {

                    alert(error.message);


                }

            );


        }

        function deleteAccount() {

            var accountId = document.getElementById("txtaccountid").value;

            parent.Xrm.WebApi.deleteRecord("account", accountId).then(

                function success(result) {

                    alert("Account deleted");


                },

                function (error) {

                    alert(error.message);


                }

            );

        }

    </script>

</head>

<body>

    <table>

        <tbody>

            <tr><td>Account ID</td><td><input id="txtaccountid" type="text" readonly=""></td></tr>

            <tr>

                <td>Account Name</td>

                <td><input id="txtname" type="text"></td>

            </tr>

            <tr><td>Main Phone</td><td><input id="txtphone" type="text"></td></tr>

            <tr><td>City</td><td> <input id="txtcity" type="text"></td></tr>

            <tr><td>Website</td><td><input id="txtwebsite" type="text"></td></tr>

            <tr><td>Total Employees</td><td><input id="txttotalemployees" type="text"></td></tr>



            <tr><td colspan="2"><input onclick="createAccount()" type="button" value="Add New">
<input onclick="deleteAccount()" type="button" value="Delete">
<input onclick="updateAccount()" type="button" value="Update"></td></tr>

        </tbody>

    </table>







</body>

</html>

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...