Tuesday, April 17, 2018

Dynamics 365-Twitter Integration


Dynamics CRM always need integration with multiple system integration.
Basically, Dynamics CRM sales and marketing module always looking for more integration with social sites like Facebook, Twitter, LinkedIn etc.
 In my last project there was a requirement to integrate Dynamics CRM Marketing Campaign with Twitter. When organization create any new campaign/promotion organization need to spread tweet about that, so customer know about their campaign and promotions.
Here, I will tell how you can integrate your Dynamics 365 with Twitter.

Step1: - Create Application in Twitter. I will demonstrate how you can create application in Twitter.

Open given URL https://apps.twitter.com/ in browser and login with our organization twitter account.















Now click on “Create New App”. And provide your application details. In website textbox enter your company web address. If you do not have any web address, use can also use CRM online address. Make sure your web address should be accessible via web. Any local website will not work.






















Now click on “Create Your Twitter Application”.
























Now my Application is created with Consumer Key. We also need Access Token to complete our application. So, click on “Create my access token” button.
Now copy your Consumer Key (API Key), Consumer Secret (API Secret), Access Token, Access Token Secret keys and save for future use. Also make sure Access level should be “Read and Write”.
Now our first step is completed.

Step 2: - Create Custom Workflow.

We need to create custom workflow to send Tweet from Dynamics CRM.
Open visual studio and create a class library project


















Right click on project and select “manage nuget package” and write TweetSharp in search bar.
Now click on install button. It will TweetSharp.dll in your project.

















Now we need to pass keys at runtime, so we need to create input arguments for Keys and our message that needs to tweet.
Create new object of TwitterService class. And call SendTweet method.
Add signature to your project. And build the solution.
Now My custom workflow is created.

Step 3: - Create a Merged assembly.

In our custom workflow we have used external assembly to call twitter. So, we need to merge all assembly in single assembly.
We have multiple option to merge assembly in single assembly. But my favorite tool is https://ilmergegui.codeplex.com/ .
Download and install this ILMerge UI.































Open ILMerge and click on “Add assembly” and select three dependent assembly and one your custom workflow assembly.



















Now select your custom workflow assembly. Mark check “Sign with key file” option and select your project signing key. Also provide output location of assembly. Than click on “Merge” button.
Now your final assembly is created.

Step 4: - Register your assembly in Dynamics CRM/365.

Now are ready with our assembly. We just need to register this in Dynamics CRM/365 and start playing with this.
If you are using new version (9.0 or higher) of Dynamics 365 old Plugin registration tool will not work.
Now register your assembly.















Now our assembly is registered.

Step 5: - Create workflow in Dynamics CRM/365.

Login to your Dynamics CRM organization and create new process.
I am using Campaign entity to send tweet. Make sure your tweet field should not have text length greater than 280.
I am also using Campaign Status Details field (Status Reason) = “Launched” to send tweet.


















Now provide your Keys details that we stored in step 1. You need to provide key information in your custom workflow calling step.
Activate your workflow.

Step 7: - Send Tweet from Dynamics CRM/365.

Create a new campaign. Enter your promotion needs to tweet. Select status reason as “Launched”.















Save the record and check your tweeter account. You will see new tweet there.

Thursday, April 5, 2018

Overview of access teams and demonstration.

Brief Description :
Access teams provide a way to share records between different functional teams without having to change or update the base security rule in Security roles. Access teams does not mean ownership of the record. The record is only shared so that other users can work on it.

Scenario:

There are two sales teams “Sales India” and “Sales Us” in different business units.The users of both the teams can read the whole organizations data but can write/edit data to only those user’s data who are in the same business unit.Here if one team member of “Sales US” wants to write/edit a record of “Sales India” it is not possible. This is where access teams comes in the picture. Some users from “Sales US” can be given access to write/edit records of “Sales India”

Steps:

Step 1:
There are two business units “Sales India”  and “Sales US”
Step 2:
Tom is a part of “Sales India Team” and Harry is a part of  “Sales US Team”.
Step 3:
Assigned both the users a custom role in which they can do the following as shown below
  1. Read account records of the whole organization,
  2. Create records at user level
  3. Write/edit records at business unit level
Step 4:
Now to enable access team we must navigate to entity for which access teams needs to be enabled as shown in figure below
Here we go to Accounts entity and enable Access Teams then to save the changes made publish all the customization.
Step 5:
To use access teams we first create an access team template by navigating to Setting > Security > Access Team Templates
Step 6:
Here create a new template with an appropriate name and select the Access Rights and the Entity as shown in the figure below.
Note:The entities field on which Acess Teams are enabled only those entities will be shown in the Entity field dropdown.
By adding users, you are granting them the access rights to that record that are defined within the access team template, even if their base security role does NOT grant them those rights. Note, the access rights are ONLY being granted for that specific record.
Step 7:
Now we add a Sub grid on the Accounts main form so that the users can be added to the access team on the fly.
Here in the Team Template field select the template made for the access team. After setting up the subgrid Save and Publish all the Customizations.
Step 8:
Harry is the owner of two records(Crook Motor Company & Lamborghini) as shown below.
Tom is the owner of one record(Tata Motors) as shown below
Step 9:
Harry can view every record in the organization but cannot write/edit. As seen below harry can only read record created by Tom.
Step 10:
Now as harry wants to write/edit this particular record, the admin has to add him in the access team sub-grid to give him access to write to this record.
Step 11:
Now Harry can write/edit to that particular record as shown below.

Wednesday, February 14, 2018

Client API execution context

We can pass the execution context in the following way.

Defining event handlers using UI: The execution context is an optional parameter that can be passed to a JavaScript library function through an event handler. Use the Pass execution context as first parameter option in the Handler Properties dialog while specify the name of the function to pass the event execution context. The execution context is the first parameter passed to a function.




The Client API form context (formContext) provides a reference to the form or to an item on the form, such as, a quick view control or a row in an editable grid, against which the current code is executed.
Earlier, the global Xrm.Page object was used to represent a form or an item on the form. With Dynamics 365 (online), version 9.0, the Xrm.Page object is deprecated, and for you should use the getFormContext method of the passed in execution context object to return reference to the appropriate form or an item on the form.

Utilizing the formContext object rather than the Xrm.Page object

Please find the below sample code for example

Using Xrm.object
Function contactDetails()
{
         var fName = Xrm.Page.getAttribute("firstname").getValue();
    var lName = Xrm.Page.getAttribute("lastname").getValue();
}

Using formContext
function contactDetails(executionContext)
{
    var formContext = executionContext.getFormContext(); //to get the formContext

    // use formContext instead of Xrm.Page 
    var fName = formContext.getAttribute("firstname").getValue();
    var lName = formContext.getAttribute("lastname").getValue();
   
}

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...