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.

Thursday 27 September 2018

Dynamics CRM : Export Security Role


In CRM as a developer sometime we need to see permission given to Security role.
Dynamics CRM/365 we need to open security role to check permission in that security role.
But there is no provision to export Security role permission.

Case Study: -
Developer X is working in an organization as support engineer. He was not part of implementation team.
User requested role given in each security role permission in excel sheet.
It is time consuming job to open each security role and make excel sheet manually with all permission.

Solution: -
To tackle this case study, I have created a XrmToolBox Plugin which help Developer X.
User can see permission given in each security role to entity.
User can see Miscellaneous Privileges.
User can export all Privileges based on selected Security role.
Download XRMToolBox from given URL and install. https://www.xrmtoolbox.com/
Install “Export Security Role” Plugin in your XRMTollBox using plugin store.























If you are not able to find “Export Security Role in Xrmtoolbox.
Use below links
Download Plugin compatible with Xrmtoolbox Version 1.2019.7.34 from here:
Download 1.2019.11.15

Download Xrmtoolbox Version 1.2019.7.34 from here:
XrmToolbox v1.2019.7.34

And download plugin from here. Install in XRMToolBox by clicking Settings->Path->Storage folder->Plugin folder.
Copy assemblies in Plugin folder.









































Connect your organization and open plugin Export Security Role.













Click on “Retrieve Roles” and select your security Role.
Now you will see list of all security roles in role list.





Now when you select any security role it will show all Privileges for selected security role.

































If need to search specific entity enter logical name in search box.











Click on Export button to export privileges in excel.
















As a result, you will see a excel file with Security role name is create with all privileges.





























Now Developer X will easily able to find and share permission based on security role.

Note: - Plugin based on .net framework 4.5.2. Microsoft office required to export result.

Follow my blog so you will not miss my new upcoming blogs.

Thursday 13 September 2018

Dynamics CRM - Sharepoint Upload Event

Dynamics 365 provide out-of-box integration with SharePoint which we used to manage our documents.
It hosts SharePoint document library in CRM page to upload or mange document.
But sadly Dynamics CRM/365 do not provide any event when document is uploaded in CRM.
Some time we to trigger an action like approval process, notification, email or task once document is uploaded.
So, in this blog I will try to counter this issue with help of Microsoft Flow.
So, let’s begin………

1. Login in O365 portal with admin permission.

2. Open SharePoint.









3. Open Flow








4. Open Dynamics 365











5. Create a new Team Site in SharePoint 















Select Public as privacy setting.
Copy Site address in notepad for use.

















Click on next than finish.

6.  Go to Dynamics 365 and setting->Document management.
7.  Click on Document Management Settings













8. For demo purpose I am only taking Contact entity for SharePoint integration.
9. Paste your site URL that we created previously.
10. Click on next and leave Select folder structure as uncheck than Next and Finish.























11. Go to Microsoft Flow and click on “Create from template” to create new flow.










12. Search for “Get a push notification when a new file is added in SharePoint” template and click on it.











13. Click on “Edit in advanced mode"

















14. Paste site URL that you create earlier. And select “Contact” in library name and leave folder as blank.
15.  Delete push notification step, we do not need this.















16. Click on “New step” and select “Add a condition”. If we do not add this condition it will create two tasks.







17. Click on “If yes” and select “Add an action"

















18. Select Dynamics 365 from connector.













19. Currently there is no template to execute an action or workflow. So, I am creating a high Priority “Task” for testing and can trigger workflow or action based on our requirement.
20. Select “Dynamics 365 – create a new record” action.



















21. Select your organization than “Task” in entity.





















22. Provide required information and save it. Now all setup is done now time for testing. We can create multiple Flow for different entities.















23. Go to any contact record and navigate to document. Upload a new document.










24. Once document is uploaded wait for few second and go to Microsoft flow to check history of your flow.




















25. Open last history.















26. If result, is successful go to Dynamics 365 to check Task is create or not.
Bingo!! Task created.















Try to use this and share your feedback.

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