Quantcast
Channel: XrmServiceToolkit - A Microsoft Dynamics CRM 2015/2013/2011 JavaScript Library
Viewing all 589 articles
Browse latest View live

Updated Wiki: Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation

$
0
0
Hi All.

There are times when I discussed with my colleagues and friends about CRM 2011 JavaScript development and how I am doing it these days. In this post, I just want to share some experience which may make your life a little bit easier when developing some complex HTML web resource for CRM 2011 using Soap, Rest, Ajax calls, etc

NOTE You can download the whole source from here

Tools required:

1. CRM 2011 on-premise installation on a server or on a virtualization environment (Windows 8 hyper-V, virtual box, VM player, etc)

2. Xrm Page Script Project Template: this can be found in the SDK: MicrosoftDynamicsCRM2011SDK\sdk\templates\xrm.pagescriptprojecttemplate. You will need to install this managed solution from the SDK to the CRM server. SDK should provide you enough details. Make sure you read the details about how to use this tool

3. VS 2010, VS 2012

4. JavaScript Libraries used: JSON2, JQuery, XrmServiceToolkit

CRM Environment:

CRM on-premise only (An actual development server, or a VM on your local PC)

Debug/Development Case:

To start with a simple example, let us just say we could like to initialize a Soap call to create a new contact using an existing account id as the parent customer of the contact. Then we will retrieve the newly created contact and show an alert message that the contact has been created successfully in the system by showing@@ the full name of the contact we just created in the alert message.

----------------------------------------------------------------------------------------------------------------------------

Once you got all of the required tools, we can get this started. We first will a Xrm.Page Jscript Library Project named it as “XrmJavaScriptDevelopment”

1.gif

clip_image004

Step 1: Add JavaScript Libraries

Before that we may need to add some helper libraries we want to use for the development. In this example, let us add several libraries like JSON2, JQuery, XrmServiceToolkit, etc

As a personal preference, I have also added some sub folders under the “Scripts” folder

clip_image006

Step 2: Generate PageData.js from

There are two ways you can get a new PageData.js

1. Use the Xrm.Page data snapshot tool to generate a new page data (covered in the readme document for XrmJavaScriptDevelopment tool)

2. Manually modify the existing file (covered in this post)

Now open PageData.js in Visual Studio

clip_image008

Because we are doing this in on-premise environment (I can only do this debugging in on-premise environment actually), the only things we actually need to change are OrgUniqueName and the ServerUrl (RU11 and before) or ClientUrl (RU12 and later). To make our example support all these rollups, you can change the line to the one showing below.

Before:

clip_image010

After:

clip_image012

Step 3: Modify TestPage.htm

Let us change the default TestPage.htm to a simple version for testing purpose of our incoming Soap/Rest call. The updated version will look like the following screenshot. Also remember to set the page as the start page in your project.

clip_image014

Notice that we have added some JavaScript reference directly from our project. As a personal preference, I always like to refer the JavaScript libraries as the order they depend on each other. This small habit may save you sometime to have to apply load scripts when you update CRM to RU12 or have to modify the sequence of JavaScript libraries.

Step 4: Modify TestPage.js

This is the main JavaScript where we will have all the Soap/Rest call to CRM 2011. Let us modify the existing code and change it as the following screenshot to start with. Later on we will add our Soap logics

clip_image016

We added some reference here which will give you JavaScript IntelliSense support when developing JavaScript in Visual Studio. Let us continue and add our Soap logics here

clip_image018

One thing to note here, because we changed the PageData.js to point to the “Vanilla” CRM instance, the Soap actually will create the records in the CRM instance.

Let us now put some breakpoints and start debugging our small code here

clip_image020

Now you can actually debug / unit test our small Soap method in visual studio instead of….well publishing the web resource into CRM, and debug

clip_image022

If we have a look at the CRM instance, there is actually a contact recorded created

clip_image024

If anything is wrong with our Soap code, we can now actually change the code directly without repeating the process to publish and change our web resource and debug using IE developer tool, Firefox FireBug, Chrome development tools, Fiddler, etc

After you have passed code checking and JavaScript Unit Testing, you can actually publish all the JavaScript Libraries, HTML, CSS without too much change.

Obviously, the names of all these files have to be updated as their CRM name when uploading into CRM as web resources.

Summary

This is just the start of what you can do using this approach. You obviously can extend this example to a much complex level as how you want to do this.

I would love to hear the community who managed to use similar approach for a HTTPS or even online environment for CRM development or anything else you could think of.

I have used this approach in many ways of the projects I have involved and saved me quite a big time to debug and test my code.

Just an example I did which is a HTML page to dynamically retrieve the auditable entities and generate the audit reports for all the records of these particular entities in the current CRM instance using XrmServiceToolkit and Metadata Retrieval. (Soap calls, CSS styling, etc) All these development works can be done locally in your visual studio.

clip_image026

Credit:

CSS styling is based on the great work of Darren Liu. You can find it at Codeplex http://crm2011templates.codeplex.com/

If any credits have not been mentioned, thanks very much for all the contributions to CRM community members. Big thanks from a learner (Me)

-------------------------------------------------------

Happy Coding,

Jaimie Ji

Updated Wiki: Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation

$
0
0
Hi All.

There are times when I discussed with my colleagues and friends about CRM 2011 JavaScript development and how I am doing it these days. In this post, I just want to share some experience which may make your life a little bit easier when developing some complex HTML web resource for CRM 2011 using Soap, Rest, Ajax calls, etc

NOTE: You can download the whole source from

Tools required:

1. CRM 2011 on-premise installation on a server or on a virtualization environment (Windows 8 hyper-V, virtual box, VM player, etc)

2. Xrm Page Script Project Template: this can be found in the SDK: MicrosoftDynamicsCRM2011SDK\sdk\templates\xrm.pagescriptprojecttemplate. You will need to install this managed solution from the SDK to the CRM server. SDK should provide you enough details. Make sure you read the details about how to use this tool

3. VS 2010, VS 2012

4. JavaScript Libraries used: JSON2, JQuery, XrmServiceToolkit

CRM Environment:

CRM on-premise only (An actual development server, or a VM on your local PC)

Debug/Development Case:

To start with a simple example, let us just say we could like to initialize a Soap call to create a new contact using an existing account id as the parent customer of the contact. Then we will retrieve the newly created contact and show an alert message that the contact has been created successfully in the system by showing@@ the full name of the contact we just created in the alert message.

Once you got all of the required tools, we can get this started. We first will a Xrm.Page Jscript Library Project named it as “XrmJavaScriptDevelopment”

1.gif

2.png

Step 1: Add JavaScript Libraries

Before that we may need to add some helper libraries we want to use for the development. In this example, let us add several libraries like JSON2, JQuery, XrmServiceToolkit, etc

As a personal preference, I have also added some sub folders under the “Scripts” folder

3.png

Step 2: Generate PageData.js from

There are two ways you can get a new PageData.js

1. Use the Xrm.Page data snapshot tool to generate a new page data (covered in the readme document for XrmJavaScriptDevelopment tool)

2. Manually modify the existing file (covered in this post)

Now open PageData.js in Visual Studio

4.gif

Because we are doing this in on-premise environment (I can only do this debugging in on-premise environment actually), the only things we actually need to change are OrgUniqueName and the ServerUrl (RU11 and before) or ClientUrl (RU12 and later). To make our example support all these rollups, you can change the line to the one showing below.

Before:

5.png

After:

6.png

Step 3: Modify TestPage.htm

Let us change the default TestPage.htm to a simple version for testing purpose of our incoming Soap/Rest call. The updated version will look like the following screenshot. Also remember to set the page as the start page in your project.

7.gif

Notice that we have added some JavaScript reference directly from our project. As a personal preference, I always like to refer the JavaScript libraries as the order they depend on each other. This small habit may save you sometime to have to apply load scripts when you update CRM to RU12 or have to modify the sequence of JavaScript libraries.

Step 4: Modify TestPage.js

This is the main JavaScript where we will have all the Soap/Rest call to CRM 2011. Let us modify the existing code and change it as the following screenshot to start with. Later on we will add our Soap logics

8.png

We added some reference here which will give you JavaScript IntelliSense support when developing JavaScript in Visual Studio. Let us continue and add our Soap logics here

9.gif

One thing to note here, because we changed the PageData.js to point to the “Vanilla” CRM instance, the Soap actually will create the records in the CRM instance.

Let us now put some breakpoints and start debugging our small code here

10.gif

Now you can actually debug / unit test our small Soap method in visual studio instead of….well publishing the web resource into CRM, and debug

11.gif

If we have a look at the CRM instance, there is actually a contact recorded created

12.gif

If anything is wrong with our Soap code, we can now actually change the code directly without repeating the process to publish and change our web resource and debug using IE developer tool, Firefox FireBug, Chrome development tools, Fiddler, etc

After you have passed code checking and JavaScript Unit Testing, you can actually publish all the JavaScript Libraries, HTML, CSS without too much change.

Obviously, the names of all these files have to be updated as their CRM name when uploading into CRM as web resources.

Summary

This is just the start of what you can do using this approach. You obviously can extend this example to a much complex level as how you want to do this.

I would love to hear the community who managed to use similar approach for a HTTPS or even online environment for CRM development or anything else you could think of.

I have used this approach in many ways of the projects I have involved and saved me quite a big time to debug and test my code.

Happy Coding,

Jaimie Ji

Updated Wiki: Documentation

$
0
0

XrmServiceToolkit is a JavaScript library which could be used to make

  • Common Methods: Change of CRM form like enable field, show field, etc
  • Rest EndPoint Methods: Create, Retrieve, Update a record, etc
  • Soap Request Methods: Create, Retrieve, Update a record, etc
  • Extension Methods: Setup Dependent OptionSet, Add Tooltip to fields, Add custom filter view to lookup field. All these methods are generic to use and configurable through editing of XML web resource.

Debug / Unit Test Soap in Visual Studio 

[Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation]

Project Highlight and Notes: CRM 2011 Rollup 12 is coming, XrmServiceToolkit 1.4.0 beta is out

New year has always been very busy for lots of people. There is no doubt for us, MSCRM consultants...

Last week, i got an email from Microsoft CRM team to notice me that my personal CRM online subscription will be updated to Rollup 12 which was exciting news because i finally have an environment to test and develop XrmServiceToolkit and make an effort to support cross browser.

The upgrade obviously is a big deal for everyone. There are some immediate problems which i have seen for the toolkit after my instance is running RU12.

Version 1.4.0 is far from perfect at its current stage to support cross browser cause there are so many things to do and so much testing to be done. A quick summary for version 1.4.0 if you are keen.

* @current version : 1.4 (beta)

* Date: January, 2013

* Dependency: JSON2, jQuery (latest or 1.7.2 above)

* Feature: Add Cross Browser Support for RU12

* Tested Platform: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1

If you have used the toolkit previously for your project, thanks very much for your support. For version 1.4.0, download and try it out using atesting environment and let me know issues and bugs.

Happy Coding,
Jaimie 

For examples with qunit, please follow the links

 Whats new:

  • Version: 1.4.0
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Feature: Add cross browser support for RU12
    • Tested Browser: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1
  • Version: 1.3.2
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Fix: Fix an issue that XrmServiceToolit.Soap is not initialized properly when calling from ribbon for CRM Online
    • Add more cross browser support before RU12
  • Version: 1.3.1
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: November, 2012
    • New Feature:
      • A logic change to improvie performance when retrieving larger number of records
    • New Function:
      • XrmServiceToolkit.Soap.QueryAll: a method to return all records (>5k+). Similar to how to use XrmServiceToolkit.Soap.QueryByAttribute
    • New Fix:
      • XrmServiceToolkit.Rest.RetrieveMultiple not returning more than 50 records
      • XrmServiceToolkit.Soap.BusinessEntity not working properly with number attribute like int, double, decimal
      • XrmServiceToolkit.Soap not handling error message properly.
  • Version: 1.3
    • Dependency: JSON2, jQuery 1.7.2 above
    • Date: July, 2012
    • New Feature:
      • jQuery integration
      • Cross Browser support. More testings are required
    • New Category and Extension:
      • jQueryXrmDependentOptionSet: A generic configurable method to setup dependent option set in CRM 2011
      • jQueryXrmFieldTooltip: A generic configurable method to setup tooltip for crm fields
      • jQueryXrmLookupCustomFilterView: A generic configurable method to add custom filter view to crm lookup field 
  • Version: 1.2
    • Dependency: JSON2
    • Date: May, 2012
    • New Fix - Create, Update, Retrieve activity with PartyList type [From, To, Cc, Bcc]
  • Version: 1.1
    • Depdendency: JSON2
    • Date: April, 2012
    • New Function - XrmServiceToolkit.Soap.Assign
    • New Function - XrmServiceToolkit.Soap.GrantAccess
    • New Function - XrmServiceToolkit.Soap.ModifyAccess
    • New Function - XrmServiceToolkit.Soap.RevokeAccess
    • New Function - XrmServiceToolkit.Soap.RetrievePrincipalAccess

Cross Browser Support

There is still a long way to go until calling the library to support real cross browser. As downloaded from Microsoft website, CRM 2011 code validation tool is used during the upgrade process. Though testings are insufficient with real or RC environment of CRM 2011 RU9 o_0!

Code Validation

Qunit Refresh and Test Results

Qunit plays a big part during the development and continous development for this project.[NOTE] Qunit is for unit testing. You do not need the part of the code in live code

Qunit test result

Code Examples in the documentation.

All code examples or most of them are using in combination with Qunit. The qunit part of the code is not required in real life situation.

Synchronous and Asynchronous

The basics of synchronous and asynchronous calls are still the same without jQuery. As the reason not too sure yet , jQuery 1.8 will not support ajax asynch=false anymore. However in reality, there will be still usage, for example onSave, synchronous calls might still required. For best practise, asynchronous calls should be used for better performance.

XrmServiceToolkit.Rest funcitons use the last boolean parameter to indicate if the method runs asychronously or synchronously. If false is assigned, then the method will run synchronously, otherwise an asynchrounous method will be called.

 

var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",
	function (result) {
		contactId = result.ContactId;
	},
	function (error) {
		alert(error.message);
	},
	false //synchronous call
);
 
var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",
	function (result) {
		contactId = result.ContactId;
	},
	function (error) {
		alert(error.message);
	},
	true //asynchronous call
);

 

XrmServiceTookit.Soap functions using the last function parameter to indicate if the method runs asychronously or synchronously. If the funciton is defined, the method will run asychronously. Otherwise, the method will be called synchronously.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols); //synchronous call
var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;
var firstName = retrievedContact.attributes['firstname'].value;
var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols, function(result){
    var familyStatusLable = result.attributes['familystatuscode'].formattedValue;	
    var firstName = result.attributes['firstname'].value;
}); //asychronous call

Numbers

CRM 2011 has number like whole number (int), floating point (double) and Decimal number (decimal), Currency (Money).

When using the soap funcitons in the library, it is recommended to include type when assigning values. It is more likely to cause issue for fields like decimal or double

//overcome limitations of numbers with type specified.... 
createContact.attributes["numberofchildren"] = { value: 2, type: "int"}; 

createContact.attributes["exchangerate"] = {value: 1.5617, type: "decimal"}; 

createContact.attributes["address1_latitude"] = { value: 1.5617, type: "double" }; 

createContact.attributes["creditlimit"] = { value: 2, type: "Money" }; 

FormattedValue

The XrmServiceToolkit.Soap functions have an extra attribute returned as formattedValue. It could be very useful if you want to return some extra information. For example, to get the lable of OptionSet. The example is synchrous.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols);
var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;//label
var familyStatusValue = retrievedContact.attributes['familystatuscode'].value; //integer

An example to create email activity using the library.

test("Test XrmServiceToolkit.Soap.Create() method to create a email activity (email)", function () {

    var createEmail = new XrmServiceToolkit.Soap.BusinessEntity("email");
    createEmail.attributes["subject"] = "Test Email subject";
    createEmail.attributes["description"] = "This email was created by the XrmServiceToolkit.Soap.Create() sample.";

    var from = [
       { id: whoamiUserId, logicalName: "systemuser", type: "EntityReference" }
    ];

    createEmail.attributes["from"] = { value: from, type: "EntityCollection" };

    var to = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["to"] = { value: to, type: "EntityCollection" };

    var cc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["cc"] = { value: cc, type: "EntityCollection" };

    var bcc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["bcc"] = { value: bcc, type: "EntityCollection" };

    createEmail.attributes["directioncode"] = true;

    emailId = XrmServiceToolkit.Soap.Create(createEmail);

    ok(guidExpr.test(emailId), "Creating an email should returned the new record's ID in GUID format. ");
  });

An example to retrieve an email is like this. The returned value of [From/To/Cc/Bcc] is an array of Entity reference.

 

 test("Test XrmServiceToolkit.Soap.Retrieve() method to retrieve a CRM record (email)", function () {

    var cols = ["subject", "description", "from", "to", "cc", "bcc", "directioncode"];
    var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", emailId, cols);

    equals(retrievedEmail.attributes['subject'].value, "Test Email subject", "Subject matches");
    equals(retrievedEmail.attributes['description'].value, "This email was created by the XrmServiceToolkit.Soap.Create() sample.", "Description Matches");
    equals(retrievedEmail.attributes['from'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['to'].type, "EntityCollection", "CRM partylist type should be EntityCollection"); ;
    equals(retrievedEmail.attributes['cc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['bcc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['directioncode'].type, "boolean", "CRM boolean type should be boolean");
 });

To get the value of an array item of the returned result. Using something like

var sender = retrievedEmail.attributes['from'][0];

Then you can get sender.id, sender.type, sender.logicalName, sender.Name per normal as a returned EntityReference value.

An example to use the GrantAccess is like this. For all other examples, please have a look at the attached aspx page.

  test("Test XrmServiceToolkit.Soap.GrantAccess() method to grant a user access to a CRM record (contact)", function () {

     var accessOptions = {
         targetEntityName: "contact",
         targetEntityId: contactId,
         principalEntityName: "systemuser",
         principalEntityId: currentUserId,
         accessRights: ["ReadAccess", "WriteAccess"]
     };

     var grantAccessResponse = XrmServiceToolkit.Soap.GrantAccess(accessOptions);
        ok(grantAccessResponse == "GrantAccess", "The current user should have the listed access to the contact");

     });

[NOTE] These functions regarding access should be combined with CRM 2011 security model and they could be useful if entities have to be controlled at record level. This obviously has to be used with consideration of user rights, security settings and all other security related configurations as the requirement of the project.

For details about how to use all these methods and updated examples. See attached .aspx page for examples.

Credi: The code example is based on Daniel Cai's CrmWebServiceKit.

XrmServiceToolkitTest.zip

Dependency

JSON2 javascript library is required in CRM 2011 as a web resource to make the library working.

jQuery 1.7.2 above is required from version 1.3

To Unit Test your code at local machine.

There is a way to test all your Rest / Soap calls directy from your development machine without modifying the library which is achieved by using the XrmPageTemplate.js and PageData.js. For details about how to using JavaScript Intellisense, please have a look at this wonderful blog

http://crmbusiness.wordpress.com/2011/12/01/crm-2011-using-javascript-intellisense-and-testpage-htm/

Once you have got the PageData.js generated from any entity, simply put it in the helper folder to replace the existing PageData.js in the source code project which you could download from the [Source Code] section here.

Now you could run and debug the XrmServiceToolkitTest.aspx from your visual studio.

Happy Coding,

Jaimie

Updated Wiki: Documentation

$
0
0

XrmServiceToolkit is a JavaScript library which could be used to make

  • Common Methods: Change of CRM form like enable field, show field, etc
  • Rest EndPoint Methods: Create, Retrieve, Update a record, etc
  • Soap Request Methods: Create, Retrieve, Update a record, etc
  • Extension Methods: Setup Dependent OptionSet, Add Tooltip to fields, Add custom filter view to lookup field. All these methods are generic to use and configurable through editing of XML web resource.

Debug / Unit Test Soap in Visual Studio 

Project Highlight and Notes: CRM 2011 Rollup 12 is coming, XrmServiceToolkit 1.4.0 beta is out

New year has always been very busy for lots of people. There is no doubt for us, MSCRM consultants...

Last week, i got an email from Microsoft CRM team to notice me that my personal CRM online subscription will be updated to Rollup 12 which was exciting news because i finally have an environment to test and develop XrmServiceToolkit and make an effort to support cross browser.

The upgrade obviously is a big deal for everyone. There are some immediate problems which i have seen for the toolkit after my instance is running RU12.

Version 1.4.0 is far from perfect at its current stage to support cross browser cause there are so many things to do and so much testing to be done. A quick summary for version 1.4.0 if you are keen.

* @current version : 1.4 (beta)

* Date: January, 2013

* Dependency: JSON2, jQuery (latest or 1.7.2 above)

* Feature: Add Cross Browser Support for RU12

* Tested Platform: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1

If you have used the toolkit previously for your project, thanks very much for your support. For version 1.4.0, download and try it out using atesting environment and let me know issues and bugs.

Happy Coding,
Jaimie 

For examples with qunit, please follow the links

 Whats new:

  • Version: 1.4.0
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Feature: Add cross browser support for RU12
    • Tested Browser: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1
  • Version: 1.3.2
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Fix: Fix an issue that XrmServiceToolit.Soap is not initialized properly when calling from ribbon for CRM Online
    • Add more cross browser support before RU12
  • Version: 1.3.1
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: November, 2012
    • New Feature:
      • A logic change to improvie performance when retrieving larger number of records
    • New Function:
      • XrmServiceToolkit.Soap.QueryAll: a method to return all records (>5k+). Similar to how to use XrmServiceToolkit.Soap.QueryByAttribute
    • New Fix:
      • XrmServiceToolkit.Rest.RetrieveMultiple not returning more than 50 records
      • XrmServiceToolkit.Soap.BusinessEntity not working properly with number attribute like int, double, decimal
      • XrmServiceToolkit.Soap not handling error message properly.
  • Version: 1.3
    • Dependency: JSON2, jQuery 1.7.2 above
    • Date: July, 2012
    • New Feature:
      • jQuery integration
      • Cross Browser support. More testings are required
    • New Category and Extension:
      • jQueryXrmDependentOptionSet: A generic configurable method to setup dependent option set in CRM 2011
      • jQueryXrmFieldTooltip: A generic configurable method to setup tooltip for crm fields
      • jQueryXrmLookupCustomFilterView: A generic configurable method to add custom filter view to crm lookup field 
  • Version: 1.2
    • Dependency: JSON2
    • Date: May, 2012
    • New Fix - Create, Update, Retrieve activity with PartyList type [From, To, Cc, Bcc]
  • Version: 1.1
    • Depdendency: JSON2
    • Date: April, 2012
    • New Function - XrmServiceToolkit.Soap.Assign
    • New Function - XrmServiceToolkit.Soap.GrantAccess
    • New Function - XrmServiceToolkit.Soap.ModifyAccess
    • New Function - XrmServiceToolkit.Soap.RevokeAccess
    • New Function - XrmServiceToolkit.Soap.RetrievePrincipalAccess

Cross Browser Support

There is still a long way to go until calling the library to support real cross browser. As downloaded from Microsoft website, CRM 2011 code validation tool is used during the upgrade process. Though testings are insufficient with real or RC environment of CRM 2011 RU9 o_0!

Code Validation

Qunit Refresh and Test Results

Qunit plays a big part during the development and continous development for this project.[NOTE] Qunit is for unit testing. You do not need the part of the code in live code

Qunit test result

Code Examples in the documentation.

All code examples or most of them are using in combination with Qunit. The qunit part of the code is not required in real life situation.

Synchronous and Asynchronous

The basics of synchronous and asynchronous calls are still the same without jQuery. As the reason not too sure yet , jQuery 1.8 will not support ajax asynch=false anymore. However in reality, there will be still usage, for example onSave, synchronous calls might still required. For best practise, asynchronous calls should be used for better performance.

XrmServiceToolkit.Rest funcitons use the last boolean parameter to indicate if the method runs asychronously or synchronously. If false is assigned, then the method will run synchronously, otherwise an asynchrounous method will be called.

 

var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",
	function (result) {
		contactId = result.ContactId;
	},
	function (error) {
		alert(error.message);
	},
	false //synchronous call
);
 
var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",
	function (result) {
		contactId = result.ContactId;
	},
	function (error) {
		alert(error.message);
	},
	true //asynchronous call
);

 

XrmServiceTookit.Soap functions using the last function parameter to indicate if the method runs asychronously or synchronously. If the funciton is defined, the method will run asychronously. Otherwise, the method will be called synchronously.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols); //synchronous call
var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;
var firstName = retrievedContact.attributes['firstname'].value;
var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols, function(result){
    var familyStatusLable = result.attributes['familystatuscode'].formattedValue;	
    var firstName = result.attributes['firstname'].value;
}); //asychronous call

Numbers

CRM 2011 has number like whole number (int), floating point (double) and Decimal number (decimal), Currency (Money).

When using the soap funcitons in the library, it is recommended to include type when assigning values. It is more likely to cause issue for fields like decimal or double

//overcome limitations of numbers with type specified.... 
createContact.attributes["numberofchildren"] = { value: 2, type: "int"}; 

createContact.attributes["exchangerate"] = {value: 1.5617, type: "decimal"}; 

createContact.attributes["address1_latitude"] = { value: 1.5617, type: "double" }; 

createContact.attributes["creditlimit"] = { value: 2, type: "Money" }; 

FormattedValue

The XrmServiceToolkit.Soap functions have an extra attribute returned as formattedValue. It could be very useful if you want to return some extra information. For example, to get the lable of OptionSet. The example is synchrous.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols);
var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;//label
var familyStatusValue = retrievedContact.attributes['familystatuscode'].value; //integer

An example to create email activity using the library.

test("Test XrmServiceToolkit.Soap.Create() method to create a email activity (email)", function () {

    var createEmail = new XrmServiceToolkit.Soap.BusinessEntity("email");
    createEmail.attributes["subject"] = "Test Email subject";
    createEmail.attributes["description"] = "This email was created by the XrmServiceToolkit.Soap.Create() sample.";

    var from = [
       { id: whoamiUserId, logicalName: "systemuser", type: "EntityReference" }
    ];

    createEmail.attributes["from"] = { value: from, type: "EntityCollection" };

    var to = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["to"] = { value: to, type: "EntityCollection" };

    var cc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["cc"] = { value: cc, type: "EntityCollection" };

    var bcc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["bcc"] = { value: bcc, type: "EntityCollection" };

    createEmail.attributes["directioncode"] = true;

    emailId = XrmServiceToolkit.Soap.Create(createEmail);

    ok(guidExpr.test(emailId), "Creating an email should returned the new record's ID in GUID format. ");
  });

An example to retrieve an email is like this. The returned value of [From/To/Cc/Bcc] is an array of Entity reference.

 

 test("Test XrmServiceToolkit.Soap.Retrieve() method to retrieve a CRM record (email)", function () {

    var cols = ["subject", "description", "from", "to", "cc", "bcc", "directioncode"];
    var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", emailId, cols);

    equals(retrievedEmail.attributes['subject'].value, "Test Email subject", "Subject matches");
    equals(retrievedEmail.attributes['description'].value, "This email was created by the XrmServiceToolkit.Soap.Create() sample.", "Description Matches");
    equals(retrievedEmail.attributes['from'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['to'].type, "EntityCollection", "CRM partylist type should be EntityCollection"); ;
    equals(retrievedEmail.attributes['cc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['bcc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['directioncode'].type, "boolean", "CRM boolean type should be boolean");
 });

To get the value of an array item of the returned result. Using something like

var sender = retrievedEmail.attributes['from'][0];

Then you can get sender.id, sender.type, sender.logicalName, sender.Name per normal as a returned EntityReference value.

An example to use the GrantAccess is like this. For all other examples, please have a look at the attached aspx page.

  test("Test XrmServiceToolkit.Soap.GrantAccess() method to grant a user access to a CRM record (contact)", function () {

     var accessOptions = {
         targetEntityName: "contact",
         targetEntityId: contactId,
         principalEntityName: "systemuser",
         principalEntityId: currentUserId,
         accessRights: ["ReadAccess", "WriteAccess"]
     };

     var grantAccessResponse = XrmServiceToolkit.Soap.GrantAccess(accessOptions);
        ok(grantAccessResponse == "GrantAccess", "The current user should have the listed access to the contact");

     });

[NOTE] These functions regarding access should be combined with CRM 2011 security model and they could be useful if entities have to be controlled at record level. This obviously has to be used with consideration of user rights, security settings and all other security related configurations as the requirement of the project.

For details about how to use all these methods and updated examples. See attached .aspx page for examples.

Credi: The code example is based on Daniel Cai's CrmWebServiceKit.

XrmServiceToolkitTest.zip

Dependency

JSON2 javascript library is required in CRM 2011 as a web resource to make the library working.

jQuery 1.7.2 above is required from version 1.3

To Unit Test your code at local machine.

There is a way to test all your Rest / Soap calls directy from your development machine without modifying the library which is achieved by using the XrmPageTemplate.js and PageData.js. For details about how to using JavaScript Intellisense, please have a look at this wonderful blog

http://crmbusiness.wordpress.com/2011/12/01/crm-2011-using-javascript-intellisense-and-testpage-htm/

Once you have got the PageData.js generated from any entity, simply put it in the helper folder to replace the existing PageData.js in the source code project which you could download from the [Source Code] section here.

Now you could run and debug the XrmServiceToolkitTest.aspx from your visual studio.

Happy Coding,

Jaimie

Updated Wiki: Documentation

$
0
0

XrmServiceToolkit is a JavaScript library which could be used to make

  • Common Methods: Change of CRM form like enable field, show field, etc
  • Rest EndPoint Methods: Create, Retrieve, Update a record, etc
  • Soap Request Methods: Create, Retrieve, Update a record, etc
  • Extension Methods: Setup Dependent OptionSet, Add Tooltip to fields, Add custom filter view to lookup field. All these methods are generic to use and configurable through editing of XML web resource.

Debug / Unit Test Soap in Visual Studio 

Project Highlight and Notes: CRM 2011 Rollup 12 is coming, XrmServiceToolkit 1.4.0 beta is out

New year has always been very busy for lots of people. There is no doubt for us, MSCRM consultants...

Last week, i got an email from Microsoft CRM team to notice me that my personal CRM online subscription will be updated to Rollup 12 which was exciting news because i finally have an environment to test and develop XrmServiceToolkit and make an effort to support cross browser.

The upgrade obviously is a big deal for everyone. There are some immediate problems which i have seen for the toolkit after my instance is running RU12.

Version 1.4.0 is far from perfect at its current stage to support cross browser cause there are so many things to do and so much testing to be done. A quick summary for version 1.4.0 if you are keen.

* @current version : 1.4 (beta)

* Date: January, 2013

* Dependency: JSON2, jQuery (latest or 1.7.2 above)

* Feature: Add Cross Browser Support for RU12

* Tested Platform: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1

If you have used the toolkit previously for your project, thanks very much for your support. For version 1.4.0, download and try it out using atesting environment and let me know issues and bugs.

Happy Coding,
Jaimie 

For examples with qunit, please follow the links

 Whats new:

  • Version: 1.4.0
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Feature: Add cross browser support for RU12
    • Tested Browser: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1
  • Version: 1.3.2
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Fix: Fix an issue that XrmServiceToolit.Soap is not initialized properly when calling from ribbon for CRM Online
    • Add more cross browser support before RU12
  • Version: 1.3.1
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: November, 2012
    • New Feature:
      • A logic change to improvie performance when retrieving larger number of records
    • New Function:
      • XrmServiceToolkit.Soap.QueryAll: a method to return all records (>5k+). Similar to how to use XrmServiceToolkit.Soap.QueryByAttribute
    • New Fix:
      • XrmServiceToolkit.Rest.RetrieveMultiple not returning more than 50 records
      • XrmServiceToolkit.Soap.BusinessEntity not working properly with number attribute like int, double, decimal
      • XrmServiceToolkit.Soap not handling error message properly.
  • Version: 1.3
    • Dependency: JSON2, jQuery 1.7.2 above
    • Date: July, 2012
    • New Feature:
      • jQuery integration
      • Cross Browser support. More testings are required
    • New Category and Extension:
      • jQueryXrmDependentOptionSet: A generic configurable method to setup dependent option set in CRM 2011
      • jQueryXrmFieldTooltip: A generic configurable method to setup tooltip for crm fields
      • jQueryXrmLookupCustomFilterView: A generic configurable method to add custom filter view to crm lookup field 
  • Version: 1.2
    • Dependency: JSON2
    • Date: May, 2012
    • New Fix - Create, Update, Retrieve activity with PartyList type [From, To, Cc, Bcc]
  • Version: 1.1
    • Depdendency: JSON2
    • Date: April, 2012
    • New Function - XrmServiceToolkit.Soap.Assign
    • New Function - XrmServiceToolkit.Soap.GrantAccess
    • New Function - XrmServiceToolkit.Soap.ModifyAccess
    • New Function - XrmServiceToolkit.Soap.RevokeAccess
    • New Function - XrmServiceToolkit.Soap.RetrievePrincipalAccess

Cross Browser Support

There is still a long way to go until calling the library to support real cross browser. As downloaded from Microsoft website, CRM 2011 code validation tool is used during the upgrade process. Though testings are insufficient with real or RC environment of CRM 2011 RU9 o_0!

Code Validation

Qunit Refresh and Test Results

Qunit plays a big part during the development and continous development for this project.[NOTE] Qunit is for unit testing. You do not need the part of the code in live code

Qunit test result

Code Examples in the documentation.

All code examples or most of them are using in combination with Qunit. The qunit part of the code is not required in real life situation.

Synchronous and Asynchronous

The basics of synchronous and asynchronous calls are still the same without jQuery. As the reason not too sure yet , jQuery 1.8 will not support ajax asynch=false anymore. However in reality, there will be still usage, for example onSave, synchronous calls might still required. For best practise, asynchronous calls should be used for better performance.

XrmServiceToolkit.Rest funcitons use the last boolean parameter to indicate if the method runs asychronously or synchronously. If false is assigned, then the method will run synchronously, otherwise an asynchrounous method will be called.

 

var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",
	function (result) {
		contactId = result.ContactId;
	},
	function (error) {
		alert(error.message);
	},
	false //synchronous call
);
 
var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",
	function (result) {
		contactId = result.ContactId;
	},
	function (error) {
		alert(error.message);
	},
	true //asynchronous call
);

 

XrmServiceTookit.Soap functions using the last function parameter to indicate if the method runs asychronously or synchronously. If the funciton is defined, the method will run asychronously. Otherwise, the method will be called synchronously.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols); //synchronous call
var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;
var firstName = retrievedContact.attributes['firstname'].value;
var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols, function(result){
    var familyStatusLable = result.attributes['familystatuscode'].formattedValue;	
    var firstName = result.attributes['firstname'].value;
}); //asychronous call

Numbers

CRM 2011 has number like whole number (int), floating point (double) and Decimal number (decimal), Currency (Money).

When using the soap funcitons in the library, it is recommended to include type when assigning values. It is more likely to cause issue for fields like decimal or double

//overcome limitations of numbers with type specified.... 
createContact.attributes["numberofchildren"] = { value: 2, type: "int"}; 

createContact.attributes["exchangerate"] = {value: 1.5617, type: "decimal"}; 

createContact.attributes["address1_latitude"] = { value: 1.5617, type: "double" }; 

createContact.attributes["creditlimit"] = { value: 2, type: "Money" }; 

FormattedValue

The XrmServiceToolkit.Soap functions have an extra attribute returned as formattedValue. It could be very useful if you want to return some extra information. For example, to get the lable of OptionSet. The example is synchrous.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols);
var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;//label
var familyStatusValue = retrievedContact.attributes['familystatuscode'].value; //integer

An example to create email activity using the library.

test("Test XrmServiceToolkit.Soap.Create() method to create a email activity (email)", function () {

    var createEmail = new XrmServiceToolkit.Soap.BusinessEntity("email");
    createEmail.attributes["subject"] = "Test Email subject";
    createEmail.attributes["description"] = "This email was created by the XrmServiceToolkit.Soap.Create() sample.";

    var from = [
       { id: whoamiUserId, logicalName: "systemuser", type: "EntityReference" }
    ];

    createEmail.attributes["from"] = { value: from, type: "EntityCollection" };

    var to = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["to"] = { value: to, type: "EntityCollection" };

    var cc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["cc"] = { value: cc, type: "EntityCollection" };

    var bcc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["bcc"] = { value: bcc, type: "EntityCollection" };

    createEmail.attributes["directioncode"] = true;

    emailId = XrmServiceToolkit.Soap.Create(createEmail);

    ok(guidExpr.test(emailId), "Creating an email should returned the new record's ID in GUID format. ");
  });

An example to retrieve an email is like this. The returned value of [From/To/Cc/Bcc] is an array of Entity reference.

 

 test("Test XrmServiceToolkit.Soap.Retrieve() method to retrieve a CRM record (email)", function () {

    var cols = ["subject", "description", "from", "to", "cc", "bcc", "directioncode"];
    var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", emailId, cols);

    equals(retrievedEmail.attributes['subject'].value, "Test Email subject", "Subject matches");
    equals(retrievedEmail.attributes['description'].value, "This email was created by the XrmServiceToolkit.Soap.Create() sample.", "Description Matches");
    equals(retrievedEmail.attributes['from'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['to'].type, "EntityCollection", "CRM partylist type should be EntityCollection"); ;
    equals(retrievedEmail.attributes['cc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['bcc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['directioncode'].type, "boolean", "CRM boolean type should be boolean");
 });

To get the value of an array item of the returned result. Using something like

var sender = retrievedEmail.attributes['from'][0];

Then you can get sender.id, sender.type, sender.logicalName, sender.Name per normal as a returned EntityReference value.

An example to use the GrantAccess is like this. For all other examples, please have a look at the attached aspx page.

  test("Test XrmServiceToolkit.Soap.GrantAccess() method to grant a user access to a CRM record (contact)", function () {

     var accessOptions = {
         targetEntityName: "contact",
         targetEntityId: contactId,
         principalEntityName: "systemuser",
         principalEntityId: currentUserId,
         accessRights: ["ReadAccess", "WriteAccess"]
     };

     var grantAccessResponse = XrmServiceToolkit.Soap.GrantAccess(accessOptions);
        ok(grantAccessResponse == "GrantAccess", "The current user should have the listed access to the contact");

     });

[NOTE] These functions regarding access should be combined with CRM 2011 security model and they could be useful if entities have to be controlled at record level. This obviously has to be used with consideration of user rights, security settings and all other security related configurations as the requirement of the project.

For details about how to use all these methods and updated examples. See attached .aspx page for examples.

Credi: The code example is based on Daniel Cai's CrmWebServiceKit.

XrmServiceToolkitTest.zip

Dependency

JSON2 javascript library is required in CRM 2011 as a web resource to make the library working.

jQuery 1.7.2 above is required from version 1.3

To Unit Test your code at local machine.

There is a way to test all your Rest / Soap calls directy from your development machine without modifying the library which is achieved by using the XrmPageTemplate.js and PageData.js. For details about how to using JavaScript Intellisense, please have a look at this wonderful blog

http://crmbusiness.wordpress.com/2011/12/01/crm-2011-using-javascript-intellisense-and-testpage-htm/

Once you have got the PageData.js generated from any entity, simply put it in the helper folder to replace the existing PageData.js in the source code project which you could download from the [Source Code] section here.

Now you could run and debug the XrmServiceToolkitTest.aspx from your visual studio.

Happy Coding,

Jaimie

Updated Wiki: Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation

$
0
0
Hi All.

There are times when I discussed with my colleagues and friends about CRM 2011 JavaScript development and how I am doing it these days. In this post, I just want to share some experience which may make your life a little bit easier when developing some complex HTML web resource for CRM 2011 using Soap, Rest, Ajax calls, etc

NOTE: You can download the whole source from http://download-codeplex.sec.s-msft.com/Download?ProjectName=xrmservicetoolkit&DownloadId=646301

Tools required:

1. CRM 2011 on-premise installation on a server or on a virtualization environment (Windows 8 hyper-V, virtual box, VM player, etc)

2. Xrm Page Script Project Template: this can be found in the SDK: MicrosoftDynamicsCRM2011SDK\sdk\templates\xrm.pagescriptprojecttemplate. You will need to install this managed solution from the SDK to the CRM server. SDK should provide you enough details. Make sure you read the details about how to use this tool

3. VS 2010, VS 2012

4. JavaScript Libraries used: JSON2, JQuery, XrmServiceToolkit

CRM Environment:

CRM on-premise only (An actual development server, or a VM on your local PC)

Debug/Development Case:

To start with a simple example, let us just say we could like to initialize a Soap call to create a new contact using an existing account id as the parent customer of the contact. Then we will retrieve the newly created contact and show an alert message that the contact has been created successfully in the system by showing@@ the full name of the contact we just created in the alert message.

Once you got all of the required tools, we can get this started. We first will a Xrm.Page Jscript Library Project named it as “XrmJavaScriptDevelopment”

1.gif

2.png

Step 1: Add JavaScript Libraries

Before that we may need to add some helper libraries we want to use for the development. In this example, let us add several libraries like JSON2, JQuery, XrmServiceToolkit, etc

As a personal preference, I have also added some sub folders under the “Scripts” folder

3.png

Step 2: Generate PageData.js from

There are two ways you can get a new PageData.js

1. Use the Xrm.Page data snapshot tool to generate a new page data (covered in the readme document for XrmJavaScriptDevelopment tool)

2. Manually modify the existing file (covered in this post)

Now open PageData.js in Visual Studio

4.gif

Because we are doing this in on-premise environment (I can only do this debugging in on-premise environment actually), the only things we actually need to change are OrgUniqueName and the ServerUrl (RU11 and before) or ClientUrl (RU12 and later). To make our example support all these rollups, you can change the line to the one showing below.

Before:

5.png

After:

6.png

Step 3: Modify TestPage.htm

Let us change the default TestPage.htm to a simple version for testing purpose of our incoming Soap/Rest call. The updated version will look like the following screenshot. Also remember to set the page as the start page in your project.

7.gif

Notice that we have added some JavaScript reference directly from our project. As a personal preference, I always like to refer the JavaScript libraries as the order they depend on each other. This small habit may save you sometime to have to apply load scripts when you update CRM to RU12 or have to modify the sequence of JavaScript libraries.

Step 4: Modify TestPage.js

This is the main JavaScript where we will have all the Soap/Rest call to CRM 2011. Let us modify the existing code and change it as the following screenshot to start with. Later on we will add our Soap logics

8.png

We added some reference here which will give you JavaScript IntelliSense support when developing JavaScript in Visual Studio. Let us continue and add our Soap logics here

9.gif

One thing to note here, because we changed the PageData.js to point to the “Vanilla” CRM instance, the Soap actually will create the records in the CRM instance.

Let us now put some breakpoints and start debugging our small code here

10.gif

Now you can actually debug / unit test our small Soap method in visual studio instead of….well publishing the web resource into CRM, and debug

11.gif

If we have a look at the CRM instance, there is actually a contact recorded created

12.gif

If anything is wrong with our Soap code, we can now actually change the code directly without repeating the process to publish and change our web resource and debug using IE developer tool, Firefox FireBug, Chrome development tools, Fiddler, etc

After you have passed code checking and JavaScript Unit Testing, you can actually publish all the JavaScript Libraries, HTML, CSS without too much change.

Obviously, the names of all these files have to be updated as their CRM name when uploading into CRM as web resources.

Summary

This is just the start of what you can do using this approach. You obviously can extend this example to a much complex level as how you want to do this.

I would love to hear the community who managed to use similar approach for a HTTPS or even online environment for CRM development or anything else you could think of.

I have used this approach in many ways of the projects I have involved and saved me quite a big time to debug and test my code.

Happy Coding,

Jaimie Ji

Updated Wiki: Documentation

$
0
0

XrmServiceToolkit is a JavaScript library which could be used to make

  • Common Methods: Change of CRM form like enable field, show field, etc
  • Rest EndPoint Methods: Create, Retrieve, Update a record, etc
  • Soap Request Methods: Create, Retrieve, Update a record, etc
  • Extension Methods: Setup Dependent OptionSet, Add Tooltip to fields, Add custom filter view to lookup field. All these methods are generic to use and configurable through editing of XML web resource.

Debug / Unit Test JavaScript Rest/Soap in Visual Studio For CRM 2011

Project Highlight and Notes: CRM 2011 Rollup 12 is coming, XrmServiceToolkit 1.4.0 beta is out

New year has always been very busy for lots of people. There is no doubt for us, MSCRM consultants...

Last week, i got an email from Microsoft CRM team to notice me that my personal CRM online subscription will be updated to Rollup 12 which was exciting news because i finally have an environment to test and develop XrmServiceToolkit and make an effort to support cross browser.

The upgrade obviously is a big deal for everyone. There are some immediate problems which i have seen for the toolkit after my instance is running RU12.

Version 1.4.0 is far from perfect at its current stage to support cross browser cause there are so many things to do and so much testing to be done. A quick summary for version 1.4.0 if you are keen.

* @current version : 1.4 (beta)

* Date: January, 2013

* Dependency: JSON2, jQuery (latest or 1.7.2 above)

* Feature: Add Cross Browser Support for RU12

* Tested Platform: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1

If you have used the toolkit previously for your project, thanks very much for your support. For version 1.4.0, download and try it out using atesting environment and let me know issues and bugs.

Happy Coding,
Jaimie 

For examples with qunit, please follow the links

 Whats new:

  • Version: 1.4.0
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Feature: Add cross browser support for RU12
    • Tested Browser: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1
  • Version: 1.3.2
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Fix: Fix an issue that XrmServiceToolit.Soap is not initialized properly when calling from ribbon for CRM Online
    • Add more cross browser support before RU12
  • Version: 1.3.1
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: November, 2012
    • New Feature:
      • A logic change to improvie performance when retrieving larger number of records
    • New Function:
      • XrmServiceToolkit.Soap.QueryAll: a method to return all records (>5k+). Similar to how to use XrmServiceToolkit.Soap.QueryByAttribute
    • New Fix:
      • XrmServiceToolkit.Rest.RetrieveMultiple not returning more than 50 records
      • XrmServiceToolkit.Soap.BusinessEntity not working properly with number attribute like int, double, decimal
      • XrmServiceToolkit.Soap not handling error message properly.
  • Version: 1.3
    • Dependency: JSON2, jQuery 1.7.2 above
    • Date: July, 2012
    • New Feature:
      • jQuery integration
      • Cross Browser support. More testings are required
    • New Category and Extension:
      • jQueryXrmDependentOptionSet: A generic configurable method to setup dependent option set in CRM 2011
      • jQueryXrmFieldTooltip: A generic configurable method to setup tooltip for crm fields
      • jQueryXrmLookupCustomFilterView: A generic configurable method to add custom filter view to crm lookup field 
  • Version: 1.2
    • Dependency: JSON2
    • Date: May, 2012
    • New Fix - Create, Update, Retrieve activity with PartyList type [From, To, Cc, Bcc]
  • Version: 1.1
    • Depdendency: JSON2
    • Date: April, 2012
    • New Function - XrmServiceToolkit.Soap.Assign
    • New Function - XrmServiceToolkit.Soap.GrantAccess
    • New Function - XrmServiceToolkit.Soap.ModifyAccess
    • New Function - XrmServiceToolkit.Soap.RevokeAccess
    • New Function - XrmServiceToolkit.Soap.RetrievePrincipalAccess

Cross Browser Support

There is still a long way to go until calling the library to support real cross browser. As downloaded from Microsoft website, CRM 2011 code validation tool is used during the upgrade process. Though testings are insufficient with real or RC environment of CRM 2011 RU9 o_0!

Code Validation

Qunit Refresh and Test Results

Qunit plays a big part during the development and continous development for this project.[NOTE] Qunit is for unit testing. You do not need the part of the code in live code

Qunit test result

Code Examples in the documentation.

All code examples or most of them are using in combination with Qunit. The qunit part of the code is not required in real life situation.

Synchronous and Asynchronous

The basics of synchronous and asynchronous calls are still the same without jQuery. As the reason not too sure yet , jQuery 1.8 will not support ajax asynch=false anymore. However in reality, there will be still usage, for example onSave, synchronous calls might still required. For best practise, asynchronous calls should be used for better performance.

XrmServiceToolkit.Rest funcitons use the last boolean parameter to indicate if the method runs asychronously or synchronously. If false is assigned, then the method will run synchronously, otherwise an asynchrounous method will be called.

 

var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",function (result) {
		contactId = result.ContactId;
	},function (error) {
		alert(error.message);
	},false //synchronous call
); 
var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",function (result) {
		contactId = result.ContactId;
	},function (error) {
		alert(error.message);
	},true //asynchronous call
);

 

XrmServiceTookit.Soap functions using the last function parameter to indicate if the method runs asychronously or synchronously. If the funciton is defined, the method will run asychronously. Otherwise, the method will be called synchronously.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols); //synchronous callvar familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;var firstName = retrievedContact.attributes['firstname'].value;
var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols, function(result){    var familyStatusLable = result.attributes['familystatuscode'].formattedValue;	    var firstName = result.attributes['firstname'].value;
}); //asychronous call

Numbers

CRM 2011 has number like whole number (int), floating point (double) and Decimal number (decimal), Currency (Money).

When using the soap funcitons in the library, it is recommended to include type when assigning values. It is more likely to cause issue for fields like decimal or double

//overcome limitations of numbers with type specified.... 
createContact.attributes["numberofchildren"] = { value: 2, type: "int"}; 

createContact.attributes["exchangerate"] = {value: 1.5617, type: "decimal"}; 

createContact.attributes["address1_latitude"] = { value: 1.5617, type: "double" }; 

createContact.attributes["creditlimit"] = { value: 2, type: "Money" }; 

FormattedValue

The XrmServiceToolkit.Soap functions have an extra attribute returned as formattedValue. It could be very useful if you want to return some extra information. For example, to get the lable of OptionSet. The example is synchrous.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols);var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;//labelvar familyStatusValue = retrievedContact.attributes['familystatuscode'].value; //integer

An example to create email activity using the library.

test("Test XrmServiceToolkit.Soap.Create() method to create a email activity (email)", function () {var createEmail = new XrmServiceToolkit.Soap.BusinessEntity("email");
    createEmail.attributes["subject"] = "Test Email subject";
    createEmail.attributes["description"] = "This email was created by the XrmServiceToolkit.Soap.Create() sample.";var from = [
       { id: whoamiUserId, logicalName: "systemuser", type: "EntityReference" }
    ];

    createEmail.attributes["from"] = { value: from, type: "EntityCollection" };var to = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["to"] = { value: to, type: "EntityCollection" };var cc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["cc"] = { value: cc, type: "EntityCollection" };var bcc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["bcc"] = { value: bcc, type: "EntityCollection" };

    createEmail.attributes["directioncode"] = true;

    emailId = XrmServiceToolkit.Soap.Create(createEmail);

    ok(guidExpr.test(emailId), "Creating an email should returned the new record's ID in GUID format. ");
  });

An example to retrieve an email is like this. The returned value of [From/To/Cc/Bcc] is an array of Entity reference.

 

 test("Test XrmServiceToolkit.Soap.Retrieve() method to retrieve a CRM record (email)", function () {var cols = ["subject", "description", "from", "to", "cc", "bcc", "directioncode"];var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", emailId, cols);

    equals(retrievedEmail.attributes['subject'].value, "Test Email subject", "Subject matches");
    equals(retrievedEmail.attributes['description'].value, "This email was created by the XrmServiceToolkit.Soap.Create() sample.", "Description Matches");
    equals(retrievedEmail.attributes['from'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['to'].type, "EntityCollection", "CRM partylist type should be EntityCollection"); ;
    equals(retrievedEmail.attributes['cc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['bcc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['directioncode'].type, "boolean", "CRM boolean type should be boolean");
 });

To get the value of an array item of the returned result. Using something like

var sender = retrievedEmail.attributes['from'][0];

Then you can get sender.id, sender.type, sender.logicalName, sender.Name per normal as a returned EntityReference value.

An example to use the GrantAccess is like this. For all other examples, please have a look at the attached aspx page.

  test("Test XrmServiceToolkit.Soap.GrantAccess() method to grant a user access to a CRM record (contact)", function () {var accessOptions = {
         targetEntityName: "contact",
         targetEntityId: contactId,
         principalEntityName: "systemuser",
         principalEntityId: currentUserId,
         accessRights: ["ReadAccess", "WriteAccess"]
     };var grantAccessResponse = XrmServiceToolkit.Soap.GrantAccess(accessOptions);
        ok(grantAccessResponse == "GrantAccess", "The current user should have the listed access to the contact");

     });

[NOTE] These functions regarding access should be combined with CRM 2011 security model and they could be useful if entities have to be controlled at record level. This obviously has to be used with consideration of user rights, security settings and all other security related configurations as the requirement of the project.

For details about how to use all these methods and updated examples. See attached .aspx page for examples.

Credi: The code example is based on Daniel Cai's CrmWebServiceKit.

XrmServiceToolkitTest.zip

Dependency

JSON2 javascript library is required in CRM 2011 as a web resource to make the library working.

jQuery 1.7.2 above is required from version 1.3

To Unit Test your code at local machine.

There is a way to test all your Rest / Soap calls directy from your development machine without modifying the library which is achieved by using the XrmPageTemplate.js and PageData.js. For details about how to using JavaScript Intellisense, please have a look at this wonderful blog

http://crmbusiness.wordpress.com/2011/12/01/crm-2011-using-javascript-intellisense-and-testpage-htm/

Once you have got the PageData.js generated from any entity, simply put it in the helper folder to replace the existing PageData.js in the source code project which you could download from the [Source Code] section here.

Now you could run and debug the XrmServiceToolkitTest.aspx from your visual studio.

Happy Coding,

Jaimie

Updated Wiki: Documentation

$
0
0

XrmServiceToolkit is a JavaScript library which could be used to make

  • Common Methods: Change of CRM form like enable field, show field, etc
  • Rest EndPoint Methods: Create, Retrieve, Update a record, etc
  • Soap Request Methods: Create, Retrieve, Update a record, etc
  • Extension Methods: Setup Dependent OptionSet, Add Tooltip to fields, Add custom filter view to lookup field. All these methods are generic to use and configurable through editing of XML web resource.

Debug / Unit Test JavaScript Rest or Soap in Visual Studio For CRM 2011

Project Highlight and Notes: CRM 2011 Rollup 12 is coming, XrmServiceToolkit 1.4.0 beta is out

New year has always been very busy for lots of people. There is no doubt for us, MSCRM consultants...

Last week, i got an email from Microsoft CRM team to notice me that my personal CRM online subscription will be updated to Rollup 12 which was exciting news because i finally have an environment to test and develop XrmServiceToolkit and make an effort to support cross browser.

The upgrade obviously is a big deal for everyone. There are some immediate problems which i have seen for the toolkit after my instance is running RU12.

Version 1.4.0 is far from perfect at its current stage to support cross browser cause there are so many things to do and so much testing to be done. A quick summary for version 1.4.0 if you are keen.

* @current version : 1.4 (beta)

* Date: January, 2013

* Dependency: JSON2, jQuery (latest or 1.7.2 above)

* Feature: Add Cross Browser Support for RU12

* Tested Platform: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1

If you have used the toolkit previously for your project, thanks very much for your support. For version 1.4.0, download and try it out using atesting environment and let me know issues and bugs.

Happy Coding,
Jaimie 

For examples with qunit, please follow the links

 Whats new:

  • Version: 1.4.0
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Feature: Add cross browser support for RU12
    • Tested Browser: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1
  • Version: 1.3.2
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Fix: Fix an issue that XrmServiceToolit.Soap is not initialized properly when calling from ribbon for CRM Online
    • Add more cross browser support before RU12
  • Version: 1.3.1
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: November, 2012
    • New Feature:
      • A logic change to improvie performance when retrieving larger number of records
    • New Function:
      • XrmServiceToolkit.Soap.QueryAll: a method to return all records (>5k+). Similar to how to use XrmServiceToolkit.Soap.QueryByAttribute
    • New Fix:
      • XrmServiceToolkit.Rest.RetrieveMultiple not returning more than 50 records
      • XrmServiceToolkit.Soap.BusinessEntity not working properly with number attribute like int, double, decimal
      • XrmServiceToolkit.Soap not handling error message properly.
  • Version: 1.3
    • Dependency: JSON2, jQuery 1.7.2 above
    • Date: July, 2012
    • New Feature:
      • jQuery integration
      • Cross Browser support. More testings are required
    • New Category and Extension:
      • jQueryXrmDependentOptionSet: A generic configurable method to setup dependent option set in CRM 2011
      • jQueryXrmFieldTooltip: A generic configurable method to setup tooltip for crm fields
      • jQueryXrmLookupCustomFilterView: A generic configurable method to add custom filter view to crm lookup field 
  • Version: 1.2
    • Dependency: JSON2
    • Date: May, 2012
    • New Fix - Create, Update, Retrieve activity with PartyList type [From, To, Cc, Bcc]
  • Version: 1.1
    • Depdendency: JSON2
    • Date: April, 2012
    • New Function - XrmServiceToolkit.Soap.Assign
    • New Function - XrmServiceToolkit.Soap.GrantAccess
    • New Function - XrmServiceToolkit.Soap.ModifyAccess
    • New Function - XrmServiceToolkit.Soap.RevokeAccess
    • New Function - XrmServiceToolkit.Soap.RetrievePrincipalAccess

Cross Browser Support

There is still a long way to go until calling the library to support real cross browser. As downloaded from Microsoft website, CRM 2011 code validation tool is used during the upgrade process. Though testings are insufficient with real or RC environment of CRM 2011 RU9 o_0!

Code Validation

Qunit Refresh and Test Results

Qunit plays a big part during the development and continous development for this project.[NOTE] Qunit is for unit testing. You do not need the part of the code in live code

Qunit test result

Code Examples in the documentation.

All code examples or most of them are using in combination with Qunit. The qunit part of the code is not required in real life situation.

Synchronous and Asynchronous

The basics of synchronous and asynchronous calls are still the same without jQuery. As the reason not too sure yet , jQuery 1.8 will not support ajax asynch=false anymore. However in reality, there will be still usage, for example onSave, synchronous calls might still required. For best practise, asynchronous calls should be used for better performance.

XrmServiceToolkit.Rest funcitons use the last boolean parameter to indicate if the method runs asychronously or synchronously. If false is assigned, then the method will run synchronously, otherwise an asynchrounous method will be called.

 

var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",function (result) {
		contactId = result.ContactId;
	},function (error) {
		alert(error.message);
	},false //synchronous call
); 
var contact = {};
contact.FirstName = "Diane";
contact.LastName = "Morgan";
contact.MiddleName = "<&>";
contact.GenderCode = { Value: 2 };
contact.CreditLimit = { Value: "2.00" };
contact.BirthDate = birthDate;
contact.DoNotEMail = true;
contact.DoNotPhone = true;

XrmServiceToolkit.Rest.Create(
	contact,
	"ContactSet",function (result) {
		contactId = result.ContactId;
	},function (error) {
		alert(error.message);
	},true //asynchronous call
);

 

XrmServiceTookit.Soap functions using the last function parameter to indicate if the method runs asychronously or synchronously. If the funciton is defined, the method will run asychronously. Otherwise, the method will be called synchronously.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols); //synchronous callvar familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;var firstName = retrievedContact.attributes['firstname'].value;
var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];
XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols, function(result){    var familyStatusLable = result.attributes['familystatuscode'].formattedValue;	    var firstName = result.attributes['firstname'].value;
}); //asychronous call

Numbers

CRM 2011 has number like whole number (int), floating point (double) and Decimal number (decimal), Currency (Money).

When using the soap funcitons in the library, it is recommended to include type when assigning values. It is more likely to cause issue for fields like decimal or double

//overcome limitations of numbers with type specified.... 
createContact.attributes["numberofchildren"] = { value: 2, type: "int"}; 

createContact.attributes["exchangerate"] = {value: 1.5617, type: "decimal"}; 

createContact.attributes["address1_latitude"] = { value: 1.5617, type: "double" }; 

createContact.attributes["creditlimit"] = { value: 2, type: "Money" }; 

FormattedValue

The XrmServiceToolkit.Soap functions have an extra attribute returned as formattedValue. It could be very useful if you want to return some extra information. For example, to get the lable of OptionSet. The example is synchrous.

var cols = ["firstname", "lastname", "middlename", "familystatuscode", "ownerid", "creditlimit", "birthdate", "donotemail", "donotphone"];var retrievedContact = XrmServiceToolkit.Soap.Retrieve("contact", contactId, cols);var familyStatusLable = retrievedContact.attributes['familystatuscode'].formattedValue;//labelvar familyStatusValue = retrievedContact.attributes['familystatuscode'].value; //integer

An example to create email activity using the library.

test("Test XrmServiceToolkit.Soap.Create() method to create a email activity (email)", function () {var createEmail = new XrmServiceToolkit.Soap.BusinessEntity("email");
    createEmail.attributes["subject"] = "Test Email subject";
    createEmail.attributes["description"] = "This email was created by the XrmServiceToolkit.Soap.Create() sample.";var from = [
       { id: whoamiUserId, logicalName: "systemuser", type: "EntityReference" }
    ];

    createEmail.attributes["from"] = { value: from, type: "EntityCollection" };var to = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["to"] = { value: to, type: "EntityCollection" };var cc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["cc"] = { value: cc, type: "EntityCollection" };var bcc = [
       { id: accountId, logicalName: "account", type: "EntityReference" },
       { id: contactId, logicalName: "contact", type: "EntityReference" }
    ];

    createEmail.attributes["bcc"] = { value: bcc, type: "EntityCollection" };

    createEmail.attributes["directioncode"] = true;

    emailId = XrmServiceToolkit.Soap.Create(createEmail);

    ok(guidExpr.test(emailId), "Creating an email should returned the new record's ID in GUID format. ");
  });

An example to retrieve an email is like this. The returned value of [From/To/Cc/Bcc] is an array of Entity reference.

 

 test("Test XrmServiceToolkit.Soap.Retrieve() method to retrieve a CRM record (email)", function () {var cols = ["subject", "description", "from", "to", "cc", "bcc", "directioncode"];var retrievedEmail = XrmServiceToolkit.Soap.Retrieve("email", emailId, cols);

    equals(retrievedEmail.attributes['subject'].value, "Test Email subject", "Subject matches");
    equals(retrievedEmail.attributes['description'].value, "This email was created by the XrmServiceToolkit.Soap.Create() sample.", "Description Matches");
    equals(retrievedEmail.attributes['from'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['to'].type, "EntityCollection", "CRM partylist type should be EntityCollection"); ;
    equals(retrievedEmail.attributes['cc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['bcc'].type, "EntityCollection", "CRM partylist type should be EntityCollection");
    equals(retrievedEmail.attributes['directioncode'].type, "boolean", "CRM boolean type should be boolean");
 });

To get the value of an array item of the returned result. Using something like

var sender = retrievedEmail.attributes['from'][0];

Then you can get sender.id, sender.type, sender.logicalName, sender.Name per normal as a returned EntityReference value.

An example to use the GrantAccess is like this. For all other examples, please have a look at the attached aspx page.

  test("Test XrmServiceToolkit.Soap.GrantAccess() method to grant a user access to a CRM record (contact)", function () {var accessOptions = {
         targetEntityName: "contact",
         targetEntityId: contactId,
         principalEntityName: "systemuser",
         principalEntityId: currentUserId,
         accessRights: ["ReadAccess", "WriteAccess"]
     };var grantAccessResponse = XrmServiceToolkit.Soap.GrantAccess(accessOptions);
        ok(grantAccessResponse == "GrantAccess", "The current user should have the listed access to the contact");

     });

[NOTE] These functions regarding access should be combined with CRM 2011 security model and they could be useful if entities have to be controlled at record level. This obviously has to be used with consideration of user rights, security settings and all other security related configurations as the requirement of the project.

For details about how to use all these methods and updated examples. See attached .aspx page for examples.

Credi: The code example is based on Daniel Cai's CrmWebServiceKit.

XrmServiceToolkitTest.zip

Dependency

JSON2 javascript library is required in CRM 2011 as a web resource to make the library working.

jQuery 1.7.2 above is required from version 1.3

To Unit Test your code at local machine.

There is a way to test all your Rest / Soap calls directy from your development machine without modifying the library which is achieved by using the XrmPageTemplate.js and PageData.js. For details about how to using JavaScript Intellisense, please have a look at this wonderful blog

http://crmbusiness.wordpress.com/2011/12/01/crm-2011-using-javascript-intellisense-and-testpage-htm/

Once you have got the PageData.js generated from any entity, simply put it in the helper folder to replace the existing PageData.js in the source code project which you could download from the [Source Code] section here.

Now you could run and debug the XrmServiceToolkitTest.aspx from your visual studio.

Happy Coding,

Jaimie


Updated Wiki: Home

$
0
0

Project Description

XrmServiceToolkit is a JavaScript library which can be used for JavaScript Development under the platform forMicrosoft Dynamics CRM 2011 environments. The library contains four major parts regarding functions.

  • Common: General Methods used for various purpose.
  • Rest: Organization Data Service functions including CRUD, Associate, Disassociate, etc
  • Soap: Organization Service functions including CRUD, Fetch, Associate, Disassociate, etc
  • Extension: jQuery extension to utilize WebResource to extend CRM 2011 including dependent OptionSet, field tooltip, add custom filter view to lookup field. (Some Methods 'Unsupported')

Debug / Unit Test JavaScript Rest or Soap in Visual Studio For CRM 2011

* Whats new:

  • Version: 1.4.0
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Feature: Add more cross browser support for RU12
    • Tested Browser: IE9, IE10, Chrome Version 24.0.1312.56 m, Firefox 18.0.1
  • Version: 1.3.2
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: January, 2013
    • New Fix: An issue where XrmServiceToolkit.Soap could not be initialized properly when calling from Ribbon for CRM Online
    • Add more cross browser support for coming RU12
  • Version: 1.3.1
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: November, 2012
    • New Feature:
      • A logic change to improvie performance when retrieving larger number of records
    • New Function:
      • XrmServiceToolkit.Soap.QueryAll: a method to return all records (>5k+). Similar to how to use XrmServiceToolkit.Soap.QueryByAttribute
    • New Fix:
      • XrmServiceToolkit.Rest.RetrieveMultiple not returning more than 50 records
      • XrmServiceToolkit.Soap.BusinessEntity not working properly with number attribute like int, double, decimal
      • XrmServiceToolkit.Soap not handling error message properly.
  • Version: 1.3
  • Dependency: JSON2, jQuery 1.7.2 above
  • Date: July, 2012
    • New Feature
      • Integration with jQuery
      • Cross Browser support (TODO: Testings for real 'cross-browser' support. Long Story)
    • New Extension:
      • JQueryXrmDependentOptionSet: Create Configurable Dependent Option Set to utilize CRM 2011 web resource.
      • JQueryXrmFieldTooltip: Create configurable tooltip for fields on CRM 2011 form
      • JQueryXrmCustomFilterView: Create configurable resource to add custom filter view to crm 2011 lookup field on the form
      • JQueryXrmFormatNotesControl: Format the notes control to allow insert, allow edit
  • Version: 1.2
  • Dependency: JSON2
  • Date: May, 2012
    • New Fix - Create, Update, Retrieve activity with Party List Type. See documentation and test page for details
  • Version: 1.1
  • Dependency: JSON2
  • Date: April, 2012
    • New Function - XrmServiceToolkit.Soap.Assign
    • New Function - XrmServiceToolkit.Soap.GrantAccess
    • New Function - XrmServiceToolkit.Soap.ModifyAccess
    • New Function - XrmServiceToolkit.Soap.RevokeAccess
    • New Function - XrmServiceToolkit.Soap.RetrievePrincipalAccess

 * Whats coming:

In the coming version (maybe 1.5), i would like to introduce two major changes which align with the roadmap of Microsoft CRM 2011 release notes. As i do not have access to any early beta to develop, test and debug for these changes. I would hope that i could catch up with the release sooner as i can.

  • Finalize Cross-Browser Support.
  • Tune performance

If you have suggestions, please also let me know.

[Credits and Licenses]

  • MSCRM 2011 Web Service Toolkit for JavaScript
    • @author Jaimie Ji
  • Credits:
    • The idea of this library was inspired by Daniel Cai's CrmWebServiceToolkit.
    • The idea of this Qunit testing was inspired by Daniel Cai's CrmWebServiceToolkit.
    • The idea of BusinessEntity was inspired by Daniel Cai && Ascentium CrmService JavaScript Library.
    • The REST Endpoint functions were inspired by MSCRM 2011 SDK javascript code and various resources from CRM websites and forums. Some of them were just copies with minor modification.
    • The Soap functions were inspired by Daniel Cai && Jamie Miley && Paul Way && Customer Effective.
    • Additional thanks to all contributors of MSCRM and i have learned a lot from you all.
  • Date: February, 2012

[Speical Thanks]

Thanks very much for JetBrains to provide me a free ReSharper open license for this project.

Features

  • Extension methods for common operations.
  • Support forsynchronous/asynchronouscall
  • Support for all models of Microsoft CRM 2011 (AD/IFD/CRM Online).
  • Lightweight and Simplicity - gives direct access to the Organization Data Service and Organization Service without having to generate SOAP request each time.

Common Functions

  • EnableField: A JavaScript Function to enable a crm field
  • DisableField: A JavaScript Functionto disable a crm field
  • ShowField: A JavaScript Functionto show a crm field
  • HideField: A JavaScript Functionto hide a crm field
  • UpdateRequiredLevel: A JavaScript Function to update the required level a crm field
  • GetObjectTypeCode: A JavaScript Function to get the object type code of a entity
  • CalculateDaysBetween: A JavaScript Function to calcuate days between two dates
  • AddNotification: A JavaScript Function to add a crm2011-like notification message on top of a form
  • ShowError: A JavaScript Function to show a alert of a error message
  • GuidsAreEqual : A JavaScript Function to check if two guids are the same
  • DisableAllControlsInTab : A JavaScript Function to disable all controls in a tab by tab number
  • DisableAllControlsInSection : A JavaScript Function to disable all controls in a section label

Rest Functions

  • Create: A JavaScript Fuction to perform a create Rest Endpoint request 
  • Retrieve: A JavaScript Fuction to perform a retrieve Rest Endpoint request
  • Update: A JavaScript Fuction to perform a update Rest Endpoint request
  • Delete: A JavaScript Fuction to perform a delete Rest Endpoint request
  • RetrieveMultiple: A JavaScript Fuction to perform a retrieveMultiple Rest Endpoint request
  • Associate: A JavaScript Fuction to perform a associate Rest Endpoint request
  • Disassociate: A JavaScript Fuction to perform a disassociate Rest Endpoint request

Soap Functions

  • Busines Entity: A JavaScript Object represents a business entity of CRM 2011
  • Execute: A JavaScript Funciton to perform a execute soap request
  • Fetch: A JavaScript Funciton to perform a fetch soap request
  • Retrieve: A JavaScript Funciton to perform a retrieve soap request
  • RetrieveMultiple: A JavaScript Funciton to perform a retrieve multiple soap request
  • Create: A JavaScript Funciton to perform a create soap request
  • Update: A JavaScript Funciton to perform a update soap request
  • Delete: A JavaScript Funciton to perform a delete soap request
  • QueryByAttribute: A JavaScript Function to perform a query by attribute soap request
  • QueryAll: A JavaScript Function to perform a query all soap request to return all records (>5k+)
  • SetState: A JavaScript Funciton to perform a set state soap request
  • Associate: A JavaScript Funciton to perform a associate soap request
  • Assign: A JavaScript Funciton to perform a assign soap request
  • RetrievePrincipalAccess: A JavaScript Funciton to perform a retrieve principal access soap request
  • GrantAccess: A JavaScript Funciton to perform a grant access soap request
  • ModifyAccess: A JavaScript Funciton to perform a modify access soap request
  • RevokeAccess: A JavaScript Funciton to perform a revoke access soap request
  • GetCurrentUserId : A JavaScript Funciton to get the id of the current user
  • GetCurrentUserBusinessUnitId : A JavaScript Funciton to get the business unit id of the current user
  • GetCurrentUserRoles : A JavaScript Funciton to get the list of the current user roles
  • IsCurrentUserRole : A JavaScript Funciton to check if the current user has certains roles

Extension Functions

  • JQueryXrmDependentOptionSet: Create Configurable Dependent Option Set to utilize CRM 2011 web resource.
  • JQueryXrmFieldTooltip: Create configurable tooltip for fields on CRM 2011 form
  • JQueryXrmCustomFilterView: Create configurable ability to add custom filter view to crm 2011 lookup field on the form
  • JQueryXrmFormatNotesControl: Format the notes control to allow insert, allow edit

Updated Wiki: Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation

$
0
0
Hi All.

There are times when I discussed with my colleagues and friends about CRM 2011 JavaScript development and how I am doing it these days. In this post, I just want to share some experience which may make your life a little bit easier when developing some complex HTML web resource for CRM 2011 using Soap, Rest, Ajax calls, etc

NOTE: You can download the whole source from http://download-codeplex.sec.s-msft.com/Download?ProjectName=xrmservicetoolkit&DownloadId=646301

Tools required:

1. CRM 2011 on-premise installation on a server or on a virtualization environment (Windows 8 hyper-V, virtual box, VM player, etc)

2. Xrm Page Script Project Template: this can be found in the SDK: MicrosoftDynamicsCRM2011SDK\sdk\templates\xrm.pagescriptprojecttemplate. You will need to install this managed solution from the SDK to the CRM server. SDK should provide you enough details. Make sure you read the details about how to use this tool

3. VS 2010, VS 2012

4. JavaScript Libraries used: JSON2, JQuery, XrmServiceToolkit

CRM Environment:

CRM on-premise only (An actual development server, or a VM on your local PC)

Debug/Development Case:

To start with a simple example, let us just say we could like to initialize a Soap call to create a new contact using an existing account id as the parent customer of the contact. Then we will retrieve the newly created contact and show an alert message that the contact has been created successfully in the system by showing@@ the full name of the contact we just created in the alert message.

Once you got all of the required tools, we can get this started. We first will a Xrm.Page Jscript Library Project named it as “XrmJavaScriptDevelopment”

1.gif

2.png

Step 1: Add JavaScript Libraries

Before that we may need to add some helper libraries we want to use for the development. In this example, let us add several libraries like JSON2, JQuery, XrmServiceToolkit, etc

As a personal preference, I have also added some sub folders under the “Scripts” folder

3.png

Step 2: Generate PageData.js from

There are two ways you can get a new PageData.js

1. Use the Xrm.Page data snapshot tool to generate a new page data (covered in the readme document for XrmJavaScriptDevelopment tool)

2. Manually modify the existing file (covered in this post)

Now open PageData.js in Visual Studio

4.gif

Because we are doing this in on-premise environment (I can only do this debugging in on-premise environment actually), the only things we actually need to change are OrgUniqueName and the ServerUrl (RU11 and before) or ClientUrl (RU12 and later). To make our example support all these rollups, you can change the line to the one showing below.

Before:

5.png

After:

6.png

Step 3: Modify TestPage.htm

Let us change the default TestPage.htm to a simple version for testing purpose of our incoming Soap/Rest call. The updated version will look like the following screenshot. Also remember to set the page as the start page in your project.

7.gif

Notice that we have added some JavaScript reference directly from our project. As a personal preference, I always like to refer the JavaScript libraries as the order they depend on each other. This small habit may save you sometime to have to apply load scripts when you update CRM to RU12 or have to modify the sequence of JavaScript libraries.

Step 4: Modify TestPage.js

This is the main JavaScript where we will have all the Soap/Rest call to CRM 2011. Let us modify the existing code and change it as the following screenshot to start with. Later on we will add our Soap logics

8.png

We added some reference here which will give you JavaScript IntelliSense support when developing JavaScript in Visual Studio. Let us continue and add our Soap logics here

9.gif

One thing to note here, because we changed the PageData.js to point to the “Vanilla” CRM instance, the Soap actually will create the records in the CRM instance.

Let us now put some breakpoints and start debugging our small code here

10.gif

Now you can actually debug / unit test our small Soap method in visual studio instead of….well publishing the web resource into CRM, and debug

11.gif

If we have a look at the CRM instance, there is actually a contact recorded created

12.gif

If anything is wrong with our Soap code, we can now actually change the code directly without repeating the process to publish and change our web resource and debug using IE developer tool, Firefox FireBug, Chrome development tools, Fiddler, etc

After you have passed code checking and JavaScript Unit Testing, you can actually publish all the JavaScript Libraries, HTML, CSS without too much change.

Obviously, the names of all these files have to be updated as their CRM name when uploading into CRM as web resources.

Summary

This is just the start of what you can do using this approach. You obviously can extend this example to a much complex level as how you want to do this.

I have used this approach in many ways of the projects I have involved and saved me quite a big time to develop, debug and test my code. You can also use this approach to develop a website, maybe even a windows 8 application consuming CRM data in the intranet environment (pure JS development).

I would love to hear the community who managed to use similar approach for a HTTPS or even online environment for CRM development or anything else you could think of.

Happy Coding,

Jaimie Ji

Updated Wiki: Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation

$
0
0
Hi All.

There are times when I discussed with my colleagues and friends about CRM 2011 JavaScript development and how I am doing it these days. In this post, I just want to share some experience which may make your life a little bit easier when developing some complex HTML web resource for CRM 2011 using Soap, Rest, Ajax calls, etc

NOTE: You can download the whole source from http://download-codeplex.sec.s-msft.com/Download?ProjectName=xrmservicetoolkit&DownloadId=646301

Tools required:

1. CRM 2011 on-premise installation on a server or on a virtualization environment (Windows 8 hyper-V, virtual box, VM player, etc)

2. Xrm Page Script Project Template: this can be found in the SDK: MicrosoftDynamicsCRM2011SDK\sdk\templates\xrm.pagescriptprojecttemplate. You will need to install this managed solution from the SDK to the CRM server. SDK should provide you enough details. Make sure you read the details about how to use this tool

3. VS 2010, VS 2012

4. JavaScript Libraries used: JSON2, JQuery, XrmServiceToolkit

5. The current logged in user has access to CRM organisation we used

CRM Environment:

CRM on-premise only (An actual development server, or a VM on your local PC)

Debug/Development Case:

To start with a simple example, let us just say we could like to initialize a Soap call to create a new contact using an existing account id as the parent customer of the contact. Then we will retrieve the newly created contact and show an alert message that the contact has been created successfully in the system by showing@@ the full name of the contact we just created in the alert message.

Once you got all of the required tools, we can get this started. We first will a Xrm.Page Jscript Library Project named it as “XrmJavaScriptDevelopment”

1.gif

2.png

Step 1: Add JavaScript Libraries

Before that we may need to add some helper libraries we want to use for the development. In this example, let us add several libraries like JSON2, JQuery, XrmServiceToolkit, etc

As a personal preference, I have also added some sub folders under the “Scripts” folder

3.png

Step 2: Generate PageData.js from

There are two ways you can get a new PageData.js

1. Use the Xrm.Page data snapshot tool to generate a new page data (covered in the readme document for XrmJavaScriptDevelopment tool)

2. Manually modify the existing file (covered in this post)

Now open PageData.js in Visual Studio

4.gif

Because we are doing this in on-premise environment (I can only do this debugging in on-premise environment actually), the only things we actually need to change are OrgUniqueName and the ServerUrl (RU11 and before) or ClientUrl (RU12 and later). To make our example support all these rollups, you can change the line to the one showing below.

Before:

5.png

After:

6.png

Step 3: Modify TestPage.htm

Let us change the default TestPage.htm to a simple version for testing purpose of our incoming Soap/Rest call. The updated version will look like the following screenshot. Also remember to set the page as the start page in your project.

7.gif

Notice that we have added some JavaScript reference directly from our project. As a personal preference, I always like to refer the JavaScript libraries as the order they depend on each other. This small habit may save you sometime to have to apply load scripts when you update CRM to RU12 or have to modify the sequence of JavaScript libraries.

Step 4: Modify TestPage.js

This is the main JavaScript where we will have all the Soap/Rest call to CRM 2011. Let us modify the existing code and change it as the following screenshot to start with. Later on we will add our Soap logics

8.png

We added some reference here which will give you JavaScript IntelliSense support when developing JavaScript in Visual Studio. Let us continue and add our Soap logics here

9.gif

One thing to note here, because we changed the PageData.js to point to the “Vanilla” CRM instance, the Soap actually will create the records in the CRM instance.

Let us now put some breakpoints and start debugging our small code here

10.gif

Now you can actually debug / unit test our small Soap method in visual studio instead of….well publishing the web resource into CRM, and debug

11.gif

If we have a look at the CRM instance, there is actually a contact recorded created

12.gif

If anything is wrong with our Soap code, we can now actually change the code directly without repeating the process to publish and change our web resource and debug using IE developer tool, Firefox FireBug, Chrome development tools, Fiddler, etc

After you have passed code checking and JavaScript Unit Testing, you can actually publish all the JavaScript Libraries, HTML, CSS without too much change.

Obviously, the names of all these files have to be updated as their CRM name when uploading into CRM as web resources.

Summary

This is just the start of what you can do using this approach. You obviously can extend this example to a much complex level as how you want to do this.

I have used this approach in many ways of the projects I have involved and saved me quite a big time to develop, debug and test my code. You can also use this approach to develop a website, maybe even a windows 8 application consuming CRM data in the intranet environment (pure JS development).

I would love to hear the community who managed to use similar approach for a HTTPS or even online environment for CRM development or anything else you could think of.

Happy Coding,

Jaimie Ji

Updated Wiki: Debug / Unit Test CRM 2011 JavaScript Rest/Soap in visual studio for on-premise CRM installation

$
0
0
Hi All.

There are times when I discussed with my colleagues and friends about CRM 2011 JavaScript development and how I am doing it these days. In this post, I just want to share some experience which may make your life a little bit easier when developing some complex HTML web resource for CRM 2011 using Soap, Rest, Ajax calls, etc

NOTE: You can download the whole source from http://download-codeplex.sec.s-msft.com/Download?ProjectName=xrmservicetoolkit&DownloadId=646301

Tools required:

1. CRM 2011 on-premise installation on a server or on a virtualization environment (Windows 8 hyper-V, virtual box, VM player, etc)

2. Xrm Page Script Project Template: this can be found in the SDK: MicrosoftDynamicsCRM2011SDK\sdk\templates\xrm.pagescriptprojecttemplate. You will need to install this managed solution from the SDK to the CRM server. SDK should provide you enough details. Make sure you read the details about how to use this tool

3. VS 2010, VS 2012

4. JavaScript Libraries used: JSON2, JQuery, XrmServiceToolkit

CRM Environment:

CRM on-premise only (An actual development server, or a VM on your local PC). The current logged in user to the environment has access to CRM organisation we used

Debug/Development Case:

To start with a simple example, let us just say we could like to initialize a Soap call to create a new contact using an existing account id as the parent customer of the contact. Then we will retrieve the newly created contact and show an alert message that the contact has been created successfully in the system by showing@@ the full name of the contact we just created in the alert message.

Once you got all of the required tools, we can get this started. We first will a Xrm.Page Jscript Library Project named it as “XrmJavaScriptDevelopment”

1.gif

2.png

Step 1: Add JavaScript Libraries

Before that we may need to add some helper libraries we want to use for the development. In this example, let us add several libraries like JSON2, JQuery, XrmServiceToolkit, etc

As a personal preference, I have also added some sub folders under the “Scripts” folder

3.png

Step 2: Generate PageData.js from

There are two ways you can get a new PageData.js

1. Use the Xrm.Page data snapshot tool to generate a new page data (covered in the readme document for XrmJavaScriptDevelopment tool)

2. Manually modify the existing file (covered in this post)

Now open PageData.js in Visual Studio

4.gif

Because we are doing this in on-premise environment (I can only do this debugging in on-premise environment actually), the only things we actually need to change are OrgUniqueName and the ServerUrl (RU11 and before) or ClientUrl (RU12 and later). To make our example support all these rollups, you can change the line to the one showing below.

Before:

5.png

After:

6.png

Step 3: Modify TestPage.htm

Let us change the default TestPage.htm to a simple version for testing purpose of our incoming Soap/Rest call. The updated version will look like the following screenshot. Also remember to set the page as the start page in your project.

7.gif

Notice that we have added some JavaScript reference directly from our project. As a personal preference, I always like to refer the JavaScript libraries as the order they depend on each other. This small habit may save you sometime to have to apply load scripts when you update CRM to RU12 or have to modify the sequence of JavaScript libraries.

Step 4: Modify TestPage.js

This is the main JavaScript where we will have all the Soap/Rest call to CRM 2011. Let us modify the existing code and change it as the following screenshot to start with. Later on we will add our Soap logics

8.png

We added some reference here which will give you JavaScript IntelliSense support when developing JavaScript in Visual Studio. Let us continue and add our Soap logics here

9.gif

One thing to note here, because we changed the PageData.js to point to the “Vanilla” CRM instance, the Soap actually will create the records in the CRM instance.

Let us now put some breakpoints and start debugging our small code here

10.gif

Now you can actually debug / unit test our small Soap method in visual studio instead of….well publishing the web resource into CRM, and debug

11.gif

If we have a look at the CRM instance, there is actually a contact recorded created

12.gif

If anything is wrong with our Soap code, we can now actually change the code directly without repeating the process to publish and change our web resource and debug using IE developer tool, Firefox FireBug, Chrome development tools, Fiddler, etc

After you have passed code checking and JavaScript Unit Testing, you can actually publish all the JavaScript Libraries, HTML, CSS without too much change.

Obviously, the names of all these files have to be updated as their CRM name when uploading into CRM as web resources.

Summary

This is just the start of what you can do using this approach. You obviously can extend this example to a much complex level as how you want to do this.

I have used this approach in many ways of the projects I have involved and saved me quite a big time to develop, debug and test my code. You can also use this approach to develop a website, maybe even a windows 8 application consuming CRM data in the intranet environment (pure JS development).

I would love to hear the community who managed to use similar approach for a HTTPS or even online environment for CRM development or anything else you could think of.

Happy Coding,

Jaimie Ji

New Post: getClientUrl instead of getServerUrl

$
0
0
I just wanted to see if anyone else has ran into issues with getServerUrl. We replaced it with getClientUrl and have avoided a few issues:
  1. IFD vs. Non-IFD, for instance a user who may have a test environment using On Prem and the production using IFD.
  2. Cross Domain 'Access Is Denied' errors were resolved by using getClientUrl. In this scenario if one user accessed using HTTP and the other accessed using HTTPS.
Is this something worth looking into for a future release or am I off somewhere?

Thanks!

Chris

New Post: Spelling errors

$
0
0
You might want to check your spelling on some of your comments in XrmServiceToolkit.js.

New Post: Spelling errors

$
0
0
Good idea...though a bit harsh to hear after my uneventful Easter weekend :)

New Post: getClientUrl instead of getServerUrl

$
0
0
Hi.

getClientUrl will be introduced in the coming release 1.4.1 which will be released within 2 weeks.

Jaimie

Created Issue: getCurrentUserId - Cannot convert the XML string to a cross-browser XML object. [1236]

$
0
0
After installing Rollup 12-13, I get "Cannot convert the XML string to a cross-browser XML object." when callling XrmServiceToolkit.Soap.GetCurrentUserId().

Commented Issue: getCurrentUserId - Cannot convert the XML string to a cross-browser XML object. [1236]

$
0
0
After installing Rollup 12-13, I get "Cannot convert the XML string to a cross-browser XML object." when callling XrmServiceToolkit.Soap.GetCurrentUserId().
Comments: ** Comment from web user: jaimieji **

Hi There.

Which version are you using at the moment?

Jaimie

Commented Issue: getCurrentUserId - Cannot convert the XML string to a cross-browser XML object. [1236]

$
0
0
After installing Rollup 12-13, I get "Cannot convert the XML string to a cross-browser XML object." when callling XrmServiceToolkit.Soap.GetCurrentUserId().
Comments: ** Comment from web user: aelsmore **

I'm using the latest stable version 1.3.2. I'll try with 1.4.0.

Commented Issue: getCurrentUserId - Cannot convert the XML string to a cross-browser XML object. [1236]

$
0
0
After installing Rollup 12-13, I get "Cannot convert the XML string to a cross-browser XML object." when callling XrmServiceToolkit.Soap.GetCurrentUserId().
Comments: ** Comment from web user: aelsmore **

Hi

Sorry, just tried with version 1.4.0 and this now works.

Andy

Viewing all 589 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>