JavaScript Promises

JavaScript promises are a way in JavaScript to write asynchronous code in a synchronous way. They are asynchronous callbacks, but in terms of error handling are much more readable. Here we will go through an example of how to use promises. We define a promise as below, with 2 parameters, resolve and reject: new Promise((resolve, reject) If the promise is resolved, we can perform an action, and if it is rejected, … Continue reading JavaScript Promises

JavaScript Callback Functions

A callback function in JavaScript is a function passed to another function that is then called after an event has occurred. This is useful when you don’t know how much time the function will take to complete, such as a call to a web API. In the simple example below, we have a function called callback() that writes to the console. We then have a function called testCallback() that calls the … Continue reading JavaScript Callback Functions

JavaScript in the Dynamics CRM Developer Toolkit

The Dynamics CRM developer toolkit allows you to manipulate JScript resources as well as other artifacts. In Dynamics CRM, create a new solution and add a new Web Resource: In Visual Studio, from the Developer Toolkit, create a new project: Now in your project, right click and select Add to packaging project: You can now add code to the file from within Visual Studio: Update and save the .js file: … Continue reading JavaScript in the Dynamics CRM Developer Toolkit

Namespaces in JavaScript

Namespaces are used to help organize code into logical groups. An example of a namespace is MyCo.ERP.Customers, which may contain code regarding ERP Customers. I could also have a namespace called MyCo.CRM.Customers. When writing an app, I can reference each piece of code using their fully qualified name to avoid confusion of what methods I would like to run. In languages like C#, namespaces are easily implemented. In JavaScript, we can … Continue reading Namespaces in JavaScript

Dynamics CRM SDK, Templates and Developer Toolkit

To install the Dynamics CRM SDK, go through these steps. First, download the relevant SDK version. Here we will install for Dynamics CRM 2013. http://www.microsoft.com/en-gb/download/details.aspx?id=40321 Select to download: Run the downloaded exe: Click to accept: Select a location to extract the files. The SDK files will then be extracted: From here, you can browse to the Templates folder to install the SDK Templates for Visual Studio. Run the VSIX file: … Continue reading Dynamics CRM SDK, Templates and Developer Toolkit

JavaScript === (Triple Equals)

The triple equals sign in JavaScript means “equality without type coersion”. That means, the type and values must both be equal. Take for example the scenario where 0 is false. If we compare with 2 equal signs, the following statement is true. This is because the equality operator converts if they are not of the same type: 0 == false // true If we compare the same 0 and false … Continue reading JavaScript === (Triple Equals)

Using Fiddler with Web API

In this post, we will examine using Fiddler to send requests and receive responses from an ASP.NET Web API. I have a Web API sample that looks like the following: There are different HTTP verbs, including: GET PUT POST DELETE The Customers API is very simple – it integrates with a SQL Server table called Customers with 2 fields – CustomerId and CustomerName, with the data: Start Fiddler. We will … Continue reading Using Fiddler with Web API

Running a .NET Console App in Silent Mode

In .NET, you may need to run your console app in silent mode. To do this, create a new console app. Our app will open a webpage using IE: To run in silent mode, set the Output type in the properties of the code to Windows Application: Now, when you run the code, it will run silently. In this case, you will see a web page open.

Passing Arguments to a Console App using C#

In this post, we will create a console app that accepts arguments or switches. In Visual Studio, create a new console app: The args parameter gives us what the user has entered, e.g: sampleapp.exe -something /i dosomething Add some code to print the arguments the user has provided. We will print the first 2 arguments: Now, run the app and provide 2 arguments. We can see when we provide SampleArg1 … Continue reading Passing Arguments to a Console App using C#

JavaScript Error Handling

JavaScript contains different ways to handle errors. One way is using try/catch/finally. In the example below, variable y does not exist. try { var x = 1 + y; console.log(t); } catch(e) { console.log(“Error: ” + e); } finally { console.log(“Run finally”); } Running this produces: Note you can also use name, message and stack to get error information: try { var x = 1 + y; console.log(t); } catch(e) … Continue reading JavaScript Error Handling