Dynamics crm 2011 javascript and crmrestkit
I find crmrestkit the easiest and fastest way to work with rest service in Microsoft Dynamics crm 2011. It's really simple, straight forward and supports both synchronous and asynchronous service calls.
In order to get started you should get:
Crmrestkit: http://crmrestkit.codeplex.com/
JSON2: https://github.com/douglascrockford/JSON-js
Jquery 1.4.2: http://code.jquery.com/jquery-1.4.2.min.js
JSON2: https://github.com/douglascrockford/JSON-js
Jquery 1.4.2: http://code.jquery.com/jquery-1.4.2.min.js
Add them to your Microsoft Dynamics crm 2011 Web resources:
Last step is to add them to the CRM form.
Now everything is ready for using the crmrestkit.
Few samples:
1) Retrieve multiple - synchronous :
1) Retrieve multiple - synchronous :
var columns = ['new_attributeId', 'new_attributeName'];
var filter = "new_attributeName eq 'WOW'";
var collection = CrmRestKit.RetrieveMultiple('EntityName', columns, filter);
if (collection != null && collection.results != null && collection.results.length > 0) {
var valId = "{" + collection.results[0].new_attributeId + "}";
var name = collection.results[0].new_attributeName;
var attribute =Xrm.Page.getAttribute("new_attribute1");
attribute.setValue([{ id: valId, name: name, entityType: "EntityName"}]);
}
2) Retrieve multiple – Asynchronous
var columns = ['new_attributeId', 'new_attributeName'];
var filter = "new_attributeName eq 'WOW'";
CrmRestKit.RetrieveMultiple('EntityName', columns, filter, function (collection) {
if (collection != null && collection.results != null && collection.results.length > 0) {
var valId = "{" + collection.results[0].new_attributeId + "}";
var name = collection.results[0].new_attributeName;
var attribute =Xrm.Page.getAttribute("new_attribute1");
attribute.setValue([{ id: valId, name: name, entityType: "EntityName"}]);
}
});
As you can see it is simple to read, write and understand.
When working with rest services remember that entities and attributes schema names are case sensitive.
In order to get the right name go to:
CRM website->setting->customization->developer resources-> Organization Data Service.
Or just go to SERVER URL/XRMServices/2011/OrganizationData.svc
In order to get the right name go to:
CRM website->setting->customization->developer resources-> Organization Data Service.
Or just go to SERVER URL/XRMServices/2011/OrganizationData.svc
Here you can find the names of the Entities, For the Attribute name just add the Entity name to the end of the link Example: SERVER URL/XRMServices/2011/OrganizationData.svc/IncidentSet()
In order to see Rest results go to RSS setting in IE and uncheck the "Automatically mark feed …"
Another great way for building the queries without mistakes is using the "Crm 2011 Odata query designer":
http://bingsoft.wordpress.com/2011/03/06/crm-2011-odata-query-designer-crm2011/
Hi,
ReplyDeleteCan we use this toolkit in MS CRM 2011 with custom entity.
Thanks
Yes you can ..
ReplyDeleteThanks Yairrose..Thanks alot
ReplyDeleteYou are Toolkit helps me a lot.
Hi,
ReplyDeleteHow can we pass filter for radio buttons,check boxes in crm 2011.
i am getting error while passing filter on radio button field.
Hi,
ReplyDeleteIn order to easily create quries you could use the "CRM 2011 OData Query Designer":
http://bingsoft.wordpress.com/2011/03/06/crm-2011-odata-query-designer-crm2011/
About the radio buttons:
(For false)
http://crm2011:5555/Basic/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=DoNotFax eq false
(For true)
http://crm2011:5555/Basic/xrmservices/2011/OrganizationData.svc/AccountSet?$filter=DoNotFax eq true
Hi,
ReplyDeleteI am getting error Bad Request when i m passing special chr in filter condition as ...
/XRMServices/2011/OrganizationData.svc/ContactSet()?$select=ContactId&$filter=FirstName eq 'D'soza'
if i pass simple name like FirstName eq 'Dsoza' then it works fine.
Best Regards,
Smith
I think you should URL encode the special chr, try using the JavaScript:escape command. I'll try it later on and let you know.
ReplyDeleteHi
ReplyDeleteNice blog.It help to create a quality code.Thanks for teach me very good information.It was so helpful.Great effort.
Hi Yairrose,
ReplyDeleteNice Blog.
I'm using Restkit in most of my operations and it works fine.
but while creating Activity Party record i'm not able to create record with multiple records in Activity Party.
For e.g i'm trying to create email record with multiple receivers.
Please give me any suggestion on same.
Your reply must appreciated.
Regards,
Mahesh
Hi,
DeleteThank you.
I guess it's all about how you build the JSON.
I've looked for some other blogs that might help you, I just don't have time right now to try it myself.
http://social.microsoft.com/Forums/en/crmdevelopment/thread/f3e68e94-2d39-4c99-a88c-d90c0fb1b871
http://mscrmshop.blogspot.com/2011/09/how-to-create-email-activity-using-rest.html
Let me know if it works.
Regards,
Yair
Nice blog.It help to create a quality code.Thanks for teach me very good information.It was so helpful.Great effort.
ReplyDeleteEcommerce Website Design and Development Company In Bangalore|Lead Magento Ecommerce Development company