Sep 26, 2019

Passing parameters to JavaScripts

Click this to see how parameters can be passed to Plug-ins.

Passing parameters to JavaScript is possible in Dynamics 365. When calling a particular method, we can see a way to pass whatever the parameters as below, apart from execution context as below.


Anyway, I find its pretty good since we can pass complex objects as Jason objects such as below;

{
    "type": "external",
    "isTaxInclude": true,
    "industryCode": 500,
        "profile": {
        "authority": "ABC Corp",
            "proficencyLevel": "Advanced",
            "jobCodes": [
                "GGG11",
                "ABX00",
                "XXY87"
            ],
        "noOfContractors":120
    }
}

If you go to debug (ad text debugger; to the code and perform operation after pressing F12) mode you will see how easy to access the different attributes with the JavaScript. Check how I see it once above Json object is passed;



If you are working with much complex Json objects, JsonPathFinder or JSONPath Finder chrome extension can help you sort the different values.

Passing parameters to JavaScript like this is particularly useful in below scenarios;

1) Same script to be used in different Forms with different parameters
2) Same script to be used in different Entities with different parameters

Anyway, one thing to keep in mind is these parameters can't be different in different environments. This is because, if a Solution is deployed with same Form, these parameters are being overridden with what is in the Solution. In other terms, this technique is NOT suitable to keep environmental specific variables.

One way to keep environmental variables is by checking the URL to determine the environment and load the variable accordingly. 

Sep 17, 2019

Programmatically populate Word Document Template

Ability to use Word document templates is one of the very useful features in Dynamics 365.

Here it is explained how to do it without any complicated steps.

Anyway, sometimes we may need to populate these templates programmatically. Below is the code snippet to do that using SetWordTemplate message.

OrganizationRequest req = new OrganizationRequest("SetWordTemplate");
req["Target"] = new EntityReference("account", new Guid("aaa19cdd-88df-e311-b8e5-6c3be5a8b200"));
req["SelectedTemplate"] = new EntityReference("documenttemplate", new Guid("9d6916e4-1033-4e03-a0e3-d15a5b133a9a"));
//if its a personal Template
//req["SelectedTemplate"] = new EntityReference("personaldocumenttemplate", new Guid("262032ac-13d9-e911-a975-000d3a37f8b9"));
svc.ExecuteCrmOrganizationRequest(req);

Anyway, this message manages to create the Document and attach to the relevant record as a Note. If its required to use this for other way, it may need to retrieve the document from the Note.