Archive

Archive for April, 2020

DataMigrationUtility – Unable to connect to the Dynamics instance

I was getting following error while connecting to dynamics instance using ‘DataMigrationUtility’ comes with SDK.

You don’t have permission to access any of the organizations in the Microsoft Common Data Service region that you specified. If you’re not sure which region your organization resides in, choose “Don’t know” for the CDS region and try again. Otherwise check with your CDS administrator.

 

MigrationUtility_1

 

Fix:

It seems the issue is with ‘DataMigrationUtility’ and following workaround resolved the issue in my case

  • Get the latest version of the ‘DataMigrationUtility’ tool.
  • In the Login screen,
    • Select ‘Online Region’
    • Leave ‘User Name’ and ‘Password’ fields blank

MigrationUtility_2

  • Click ‘Login’
  • Tool will prompt you the credentials in a new popup.
  • Enter your credentials and ‘Connect’

Notes:

  • I tried by unchecking ‘Show Advanced’ option but had no luck.
  • Also, I could not connect when I chose “Don’t Know” option in ‘Online Region’ field and left the ‘User Name’ and ‘Password’ fields blank.
  • The exact combination specified in ‘Fix’ worked for me.
  • After the workaround, I could connect to the Dynamics instance from ‘DataMigrationUtility’ normally from next time.

🙂

StyleCop error – The parameter is incorrect

Other day, I encountered following error while triggering ‘Run StyleCop‘ from Visual Studio.

StyleCop_Error

Reason & Fix:

  • In my case, I cloned a DevOps branch and ran the ‘Run StyleCop’ without building the code.
  • Since there were no executable’s, StyleCop thrown error ‘The parameter is incorrect‘.
  • Build the solution and ‘Run StyleCop’ should fix the issue.

StyleCop_Error_1

🙂

XML External Entity Injection – Fix

We have a Web Service, which accepts ‘XML’ payload from client and processes.

Recently the ‘Web Service’ underwent Penetration testing (Also called ‘Ethical hacking’) and following vulnerability has been identified:

PenTest_1

Reason:

  • Our Web Service, processes the XML payload submitted by client using the following code snippet:

PenTest_2

  • We were not having XML payload validation in place.
  • There is possibility that hacker can inject malicious content in the XML and can cause a denial of service condition, gain access to unauthorized information available on the server where the ‘Web Service’ was hosted.

Fix:

  • We could fix the issue by setting ‘XmlResolver’ property to ‘Null’.
  • External resources are resolved using the ‘XmlResolver’ provided via XmlDocument.XmlResolver property, by setting ‘XMlResolver’ to Null, XML Parser would not resolve the external resources, which prevents accessing external resources (i.e., Files in the Serer where Web Service hosted).
  • Change the ‘XmlDocument’ object instantiation as below with ‘XmlResolver’ set to ‘Null’ solved our issue.

var xmlDocument = new XmlDocument { XmlResolver = null };

🙂

Azure DevOps – Unable to ‘Pull’ changes from Visual Studio

I have an Azure DevOps Repo cloned to VS 2017 and ‘Pull’ command was not download and merging the remote repo.

‘Pull’ command update the code in your local repo with the changes from other members of your team. To know more about ‘Pull’ command refer here

Following steps worked as workaround for me.

  • Download and install the Git tools from here
  • From the Visual Studio’s ‘Team Explorer’, go to ‘Sync’.

git_5

  • From ‘Actions’ menu select ‘Open Command Prompt’, which opens up ‘Command Prompt’ where we can run ‘git’ commands.

git_

  • Run the command ‘git pull origin master‘ to fetch and merge the chages of other team members from the default repo ‘Master’. Change the repo name if you want.
  • System would fetch all the code commits by your team members and merge to your local repo.

git_3

  • Run the command again to make sure all the commits were merged to your local repo. You would get ‘Already up to date.’ message as below.

git_4

🙂

Categories: Azure Tags: , ,

[Step by Step] Using TypeScript in Dynamics 365 9.x

What is TypeScript:

  • TypeScript extends JavaScript by adding types to the language. TypeScript sits as a layer on-top of JavaScript, this layer is the TypeScript type system.
  • In a layman terms, TypeScript allows C# way of writing jScript.

In this article, lets see how to leverage TypeScript capability while writing client scripts in Dynamics 365.

Key Notes:

  • TypeScript’s file extension is ‘.ts‘.
  • Dynamics 365 cannot understand TypeScript, it only understands jScript (i.e., .js)
  • So we write the script in TypeScript, and use ‘Transpile’ technique to convert TypeScript to jScript.
    • Transpiling is taking source code written in one language and transforming into another language. In our case its from .ts to .js
    • Don’t worry about Transpiling as Visual Studio will take care of this.

Now we know the basics of TypeScript, lets get started.

Setting up project in Visual Studio:

  • Create a new Web Site project in Visual Studio.

TS_4

  • As we are going to Transpile TypeScript files to jScript files, create a new folders ‘ts’ and ‘js’ for code manageability.
    • ‘ts’ folder is where we write the TypeScript, ‘js’ folder is where the transpiled jScript resides.

TS_5

  • Next, to transpile TypeScript to jScript, add a new json file with name ‘tsconfig.json‘.

TS_6

  • Paste following statements and save.

{
“compileOnSave”: true,
“compilerOptions”: {
“outDir”: “js”,
“target”: “es5”,
“sourceMap”: true
},
“include”: [
“./ts/**/*”
]
}

  • Your ‘tsconfig.json’ should look like below.

TS_7

  • If you observe the ‘tsconfig.json’ statements, they state that whenever you save ‘.ts’ file compile (i.e., compileOnSave’) and save the transpiled ‘.js’ file under ‘js’ folder (i.e., outDir).
  • Next, lets install the ‘xrm’ npm package for intellisence to your project. Refer this article for more details.

TS_8

  • Run ‘–save @types/xrm‘ command.

TS_9

  • You would see a new folder ‘node_modules’ with ‘index.d.ts’ file.
    • If you are wondering what is ‘index.d.ts’, ‘*.d.ts’ files are used to provide typescript ‘Type’ information.

TS_10

Write your first TypeScript file:

Now that we got the project setup, lets write a simple ‘TypeScript’ file with ‘onload’ function on ‘Contact’ entity.

  • Add a new file ‘contact.ts’ under ‘ts’ folder.
  • Lets adding following basic structure contains ‘interface’ and ‘onload’ function.
    • A namespace is a way that is used for logical grouping of functionalities. It allows us to organize our code in a much cleaner way.

TS_13

  • Now, lets extend the onload function by reading Contact Name from ‘name’ field and popup.

TS_14

  • Lets extend further by registering ‘onchange’ event on ‘Contact Name’ field.

TS_15

  • Save the ‘contact.ts’ file and you would get transpiled ‘contact.js’ jScript file under ‘js’ folder.

TS_16

  • Following the TypeScript code if you want to use.

namespace Pract {
export function onload(executionContext: Xrm.Events.EventContext) {
let formContext = executionContext.getFormContext();

// Define ‘String Attribute’ variable to read Contact Name Attribute
let attrContactName: Xrm.Attributes.StringAttribute;
attrContactName = formContext.getAttribute<Xrm.Attributes.StringAttribute>(“firstname”);

// Register onchange event
attrContactName.addOnChange(this.contactName_onchange);

// Read Attribute Value
let contactName = attrContactName.getValue();

var alertStrings = { confirmButtonLabel: “Yes”, text: contactName, title: “Onload Event” };
var alertOptions = { height: 120, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
function success(result) {
console.log(“Alert dialog closed”);
},
function (error) {
console.log(error.message);
}
);
}

function contactName_onchange(executionContext: Xrm.Events.EventContext) {
alert(“OnChange triggered!”);
}
}

Register and test the script:

  • Add the transpiled ‘contact.js’ file as web resource to Dynamics application.
  • On ‘Contact’ form register the ‘onload’ event. Convention should be ‘namespace.functionname’ (i.e.,Pract.onload).

TS_1

  • Open the ‘Contact’ record and you would get the ‘Name’ value as pop-up.

TS_3

🙂

 

Categories: Dynamics 365 Tags: ,