Wednesday, 3 July 2019

How to use post man with Dynamics CRM 365

With Dynamics 365, Web API use become quite popular and also Microsoft promoting Web API more than other CRUD operation method.
So, sometime we need to execute our web API queries to test or build in JS or HTML web resource or other places.

For this Postman is a great tool to execute or Test our Web API.

In this blog I will try to explain how we can use Postman with Dynamics CRM 365.

 1. Download and Install Postman in your local system. (Download)

 

2. Open Postman and create click on environment to create new environment.














3. Enter Name and add variables to use in later queries.



















Sample Data:-
Name- Demo CRM

Variable
Initial Value
Current Value
url
https://crmorg.crm8.dynamics.com
https://crmorg.crm8.dynamics.com
version
9.1
9.1
webapiurl
{{url}}/api/data/v{{version}}/
{{url}}/api/data/v{{version}}/
Token
Enter token value
Enter token value

4. To get Token Open (http://xrm.tools/) and Sign In with CRM credentials. You also need to accept Consent.

5. Click on "Access Token" link from right side menu.

 Select your organization and click on "Copy to clipboard".









Add copied Token in Postman your environment variable(Token).

6. Create New Collection.





























Go to “Authorization” tab.
Select Type->Bearer Token
Enter {{Token}} variable in token.




6. Create New Request and Select your collection.



    Below are the request we can use in Postman.

1. Retrieve Multiple:-






Select “Get” method.

        Enter “{{webapiurl}}/entity plural name” and click on Send button.

2. Using FetchXML



Select “Get” method.
       Enter “{{webapiurl}}/entity plural name”fetchXml=your fetchxml query” and click on Send button.

3. Delete Record



Select “DELETE” method.
      Enter “{{webapiurl}}/entity plural name(Entity record Guid)” and click on Send button.    


4. Update










Select “PATCH” method.
Enter “{{webapiurl}}/entity plural name(Entity record Guid)”

Select Body Tab(Json(application/json)
Enter your information. 
       Click on Send button

5. Create


Select “POST” method.
Enter “{{webapiurl}}/entity plural name”
Select Body Tab(Json(application/json)
Enter your information. 
       Click on Send button.

You can use below reference to get more information on Postman operations:-



Share your feedback and follow blog to be updated !!















Saturday, 13 April 2019

Dynamics CRM and Gmail Integration


Dynamics 365 online licensing works mainly on subscription based. Customer Engagement Plan provides access to use all modules (Sales, Marketing, Customer Service, Project Service and Field Service) of Dynamics 365. But it not provide access to Email outlook subscription. We need to add outlook in subscription or other exchange server. But here we are discussing to use Gmail as Email sender in Dynamics 365 .

Dynamics 365 allows Gmail Integration. We can configure both Gmail personal and work/corporate account.
We can use this setting in CRM trial version to send emails.
Steps to configure Gmail Integration:-
1. Login to your Gmail account.
Open Setting and go to Forwarding and POP/IMAP tab.



















POP download section:-
Select “Enable POP for mail arrives from now on” option.
Select “archive Gmail’s copy” option in “When messages are accessed with POP”
Click on “Save Changes”.

2. We also need to allow our Gmail account for “Less secure app access”.
Toggle Allow less secure apps: ON
       










When we enable this feature, we will receive notification from Gmail. We need to ignore this notification.

3. Login in Dynamics 365.
Go to setting area and select “Email Configuration” from sub area from sitemap.









Click on “Email Server Profiles”
Click on “New” button and select “POP3/SMTP Server”.










Provide information:
Name-“Gmail Online”.
Incoming Server Location- pop.gmail.com
Outgoing Server Location- smtp.gmail.com
Authenticate Using- Credentials Specified by a User or Queue 
















Go to Advance Tab
Incoming Port-995
Outgoing Port-587








Save the profile.

4. Click on “Set As Default” Button.
You can use this email profile. I am creating separate Queue for Gmail.

5. Go to Setting->Service Management and select Queues.
















6. Click on “New” button.
Name- Gmail Queue
Type-Private
Incoming Email- <Your email id> Ex: test@gmail.com
Click on save button.
























7. Open “Mailbox” lookup from Email settings tab.
Provide User Name and Password.
Check serve Profile should be you Gmail profile.
Outgoing Email- Server- Side Synchronization.














8. Save the Mailbox and click on “Approve Email”.







9. Click on “Test & Enable Mailbox”. It will ask for sync permission, enable check box and click on “OK” button.















10. You will receive “Critical security alert” email from Google in your Gmail account.
Open that message and click on “Check activity” button.
Now click on “Yes” button to allow sign-in.

11. Again click on “Test & Enable Mailbox”. Now you will receive an email in Gmail account stated “Your mailbox is now connected to Dynamics 365”.

Now we have completed Dynamics 365 and Gmail configuration.

Create new Email and select “Gmail Queue” in from and in To contact with valid Email address and click on “SEND” button.


















Share your feedback and Happy CRMING!! J


Thursday, 29 November 2018

Dynamics Portal-Note Required Based On Quick View Form Value


Microsoft Dynamics Portal provides capability to allow login customers without needed any license. Here I am not explaining benefits of Dynamics Portal. I am going to show a use case for developers.

Case Study: - There is a requirement in portal where we need to make attach note section mandatory based on value of quick view form.  Now Quick view form is supported by Dynamics Portal. So, it is nice to use Quick view form to show information based on lookup value.
While creating a case from portal, customer needs to select reason (lookup field). On selection of this lookup Quick view form displayed with required document list and a Boolean field which specify document is required or not.

Based on this Boolean field value need to make attachment required or not.


















Solution: - We need to use Javascript to complete this requirement.
  • Login to Dynamics Portal with Administrator rights.
  • Click on “My Support” button than “Open a New Case” button.
  • Once create case page is opened click on edit button.












  • Once edit section is opened, click on “Option” tab.
  • Now add your Javascript code in “Custom JavaScript” text block.
















  • Click on Save button.
JavaScript Code 

/////////////////////////////////  Code Started ///////////////////////////////////////////

$(document).ready

(

function () {
    $('iframe#MandatoryInformation').load(function () {
        setTimeout(getdoc, 50);


    });
     
}
);

function getdoc() {
    let iframe = document.getElementById("MandatoryInformation");
    var innerDoc = (iframe.contentDocument)
        ? iframe.contentDocument
        : iframe.contentWindow.document;
    // check document requirement
    let isDocRequired = innerDoc.getElementById("boolean_field_schemaName_1");
    if (isDocRequired) {
        if (isDocRequired.checked) {
            //make attachment  mandatory
            addNoteValidator("AttachFile", "AttachFileLabel");

        }
        else {
            //make attachment non mandatory
            removeNoteValidator("AttachFile", "AttachFileLabel");
        }
    }
    else {
        //make attachment non mandatory
        removeNoteValidator("AttachFile", "AttachFileLabel");
    }

}
function addNoteValidator(fieldName, fieldLabel) {


    if (typeof (Page_Validators) == 'undefined') return;
    // Create new validator
    $("#" + fieldLabel).parent().addClass("required");

    var newValidator = document.createElement('span');
    newValidator.style.display = "none";
    newValidator.id = "RequiredFieldValidator" + fieldName;
    newValidator.controltovalidate = "casetypecode";
    newValidator.errormessage = "<a href='#" + fieldLabel + "'>" + "Make sure you should attach all required documents.</a>";
    newValidator.validationGroup = "";
    newValidator.initialvalue = "";
    newValidator.evaluationfunction = function () {
        var value = $("#" + fieldName).val();
        if (value == null || value == "") {
            return false;
        } else {
            return true;
        }
    };

    // Add the new validator to the page validators array:
    Page_Validators.push(newValidator);

    // Wire-up the click event handler of the validation summary link
    $("a[href='#" + fieldLabel + "']").on("click", function () { scrollToAndFocus(fieldLabel + '', fieldName); });
}
function removeNoteValidator(fieldName, fieldLabel) {
    $.each(Page_Validators, function (index, validator) {
        if (validator.id == "RequiredFieldValidator" + fieldName) {
            Page_Validators.splice(index, 1);
        }
    });

    $("#" + fieldLabel + "").parent().removeClass("required");
}

/////////////////////////////////  Code Ended///////////////////////////////////////////

Code Explanation: -  
  • On Load of create case page we are adding “On Load” event to our Iframe.  This event will fire on change to content of your “Quick View Form”.

















    $('iframe#MandatoryInformation').load(function () {
// use setTimeout to complete Iframe load.
        setTimeout(getdoc, 50);
    });
  • Timeout is used because Iframe takes some time to load completely.
  • Select Iframe content

    let iframe = document.getElementById("MandatoryInformation");

    var innerDoc = (iframe.contentDocument)
        ? iframe.contentDocument
        : iframe.contentWindow.document;
  • check document requirement field value

    let isDocRequired = innerDoc.getElementById("boolean_field_schemaName_1");
    if (isDocRequired) {
        if (isDocRequired.checked) {
  • Make attachment mandatory if Boolean in true

addNoteValidator("AttachFile", "AttachFileLabel");
  • Remove attachment mandatory if Boolean in false

  removeNoteValidator("AttachFile", "AttachFileLabel");

Result: -
  • If Field value is true.

























  • If Field value is false.

Share your feedback and follow blog to be updated !!


Tuesday, 6 November 2018

Dynamics CRM: Sent Email Template With Conditional Image


In Dynamics CRM we use Email activity a lot to send all kind of notification and approval.  CRM also provide Email Template that we can use to send customize email.
But some time we need to extend this capability.

Sample Case: - We need to send email to customer based on case origin type with below conditions.
  • We need to use embedded image. We cannot use global image hosted on public domain.
  • We need to use web resource images of CRM.
  • Need to use Email template.
  • Image need to change based on case origin value.


Solution: - After lot of research and try different solution. We conclude that we need to perform below task to achieve our requirement.
  • Need base64 string with html image tag to insert in email.
  • Need to create an email to set sender and receiver value.
  • We need email template information not to send just to get body and subject value.
  • Need to create our custom placeholder and replace these placeholder as per our requirement.

To achieve this we need some custom workflow activity for:
  • Convert web resource to base64 image string
  • Get email template subject and description at run time and set these values in our email
  • To replace our placeholders
  • Send Email

Steps: -
  1.  Create PNG Web resource to store images.







      2. Create an action to get web resource to base64 image string based on condition. Use Getbase64Image custom workflow.




























   3. Create placeholder in your Email template. I have use [url] as placeholder.

















4. Create Workflow to complete our requirement and send email
·         Call previously create action to get embedded image.
·         In next step create an email set to and from value.
·         In next step call update email from email template custom workflow. This workflow will use Instantiate Template Request because do not need to send this email template. We need it’s Subject and description value.

InstantiateTemplateRequest instTemplateReq = new InstantiateTemplateRequest
                {
                    TemplateId = EmailTemplate.Get(executionContext).Id,
                    ObjectId = Case.Get(executionContext).Id,
                    ObjectType = Case.Get(executionContext).LogicalName
                };
InstantiateTemplateResponse instTemplateResp = (InstantiateTemplateResponse)service.Execute(instTemplateReq);
  Entity emailT = (Entity)instTemplateResp.EntityCollection.Entities[0];
Entity email = service.Retrieve(EmailSource.Get(executionContext).LogicalName, EmailSource.Get(executionContext).Id, new ColumnSet("description", "subject"));
  email.Attributes["description"] = emailT.Attributes.Contains("description") ? (String)emailT.Attributes["description"] : "";
email.Attributes["subject"] = emailT.Attributes.Contains("subject") ? (String)emailT.Attributes["subject"] : "";
service.Update(email);

 5.  Call Replace Placeholder workflow to update placeholder with embedded image.
 6.  Finally send this email. 

















I have not considered email Template with attachment. For Email Template with attachment you need to extend “update email from email template” custom workflow.

Result: -













I am sharing custom workflow assembly. Hope this will help other also.

Field Security Profile - Based on Owner

 Recently received requirement related to Field security profile. Expectation : - 1.       Set to users need access of secure attributes. 2....

Test