// JScript source codeproductnumber = function () {
if (Xrm.Page.getAttribute("productid").getValue() != null) {
prdid = Xrm.Page.getAttribute("productid").getValue()[0].id;
this.retrieveRecord(prdid, "Product", null, null, function (res) { this.successCallback(res) }, function () { alert(‘Error’); });
}
}function successCallback(results) {
debugger;
var prdnumber = results.ProductNumber;
var quan=results.QuantityOnHand;
Xrm.Page.getAttribute("productnumber").setValue(prdnumber);
Xrm.Page.getAttribute("availablequantity").setValue(quan);
}retrieveRecord = function (id, type, select, expand, successCallback, errorCallback) {var systemQueryOptions = "";if (select != null || expand != null) {
systemQueryOptions = "?";
if (select != null) {
var selectString = "$select=" + select;
if (expand != null) {
selectString = selectString + "," + expand;
}
systemQueryOptions = systemQueryOptions + selectString;
}
if (expand != null) {
systemQueryOptions = systemQueryOptions + "&$expand=" + expand;
}
}
var req = new XMLHttpRequest();
var surl = Xrm.Page.context.getServerUrl();
var url = http://localhost:5555/testing/XRMServices/2011/OrganizationData.svc/ + type + "Set(guid’" + id + "’)" + systemQueryOptions;
req.open("GET", url, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 200) {
successCallback(JSON.parse(this.responseText, this._dateReviver).d);
}
else {
errorCallback(this._errorHandler(this));
}
}
};
req.send();
}_dateReviver: function (key, value) {
///<summary>
/// Private function to convert matching string values to Date objects.
///</summary>
///<param name="key" type="String">
/// The key used to identify the object property
///</param>
///<param name="value" type="String">
/// The string value representing a date
///</param>var a;
if (typeof value === ‘string’) {
a = /Date\(([-+]?\d+)\)/.exec(value);
if (a) {
return new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
}
}
return value;
}function errorHandler(error) {
writeMessage(error.message);
}
This tutorial is targeted for Microsoft Dynamics CRM developers beginning to learn Dynamics CRM.
Thursday, March 21, 2013
CRM 2011 Retrieve values from other entity based on lookup value.
Get and Set lookup value using javascript in CRM 2011
var lookup = new Array();
lookup = Xrm.Page.getAttribute("attributename").getValue();
if (lookup != null) {
var name = lookup[0].name;
var id = lookup[0].id;
var entityType = lookup[0].entityType;
}
Set a lookup value
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = recorid;
lookup[0].name = recordname;
lookup[0].entityType = entityname;
Xrm.Page.getAttribute("attributename").setValue(lookup);
Alternate method to set lookup value
Xrm.Page.getAttribute("attributename").setValue([{ id: recorid, name: recordname, entityType: entityname}]);
How to retrieve lookup text value / id using Javascript in CRM 2011 OR How to get lookup text value / Id in CRM 2011
get lookup value and id using javascript in mscrm 2011
{
var lookupObject = Xrm.Page.getAttribute("primarycontactid");
if (lookupObject != null)
{
var lookUpObjectValue = lookupObject.getValue();
if ((lookUpObjectValue != null))
{
var lookuptextvalue = lookUpObjectValue[0].name;
alert(lookuptextvalue);
var lookupid = lookUpObjectValue[0].id;
alert(lookupid);
}
}
}
CRM 2011 JavaScript Library Methodology
Introduction
If you've ever worked on a large CRM project or had to deal with a CRM 4 upgrade of any size you may quickly find yourself in a sea of JavaScript that can begin to look a little overwhelming. Personally I loathe most JavaScript that comes my way because you tend to get these 5 page long methods that do everything, all the field names are hard coded strings and option sets/form event mode constants are all numeric values so you can't just read the code and quickly understand what it is doing. To make matters worse JavaScript is not like coding in C# so there are so many more opportunities for things to go wrong. Since JavaScript is very loose and the tools available at the moment aren't very strong in design time error and dependency checking are not up to par with managed code it will pay big dividends to try and be a little stricter up front when it comes to writing your client side code and keeping those libraries organized.
The following is my conceptual working model that I'm working on as I've had to deal with development issues during my travels. Mind you I have not yet had an opportunity to implement this in an actual project yet so let's just call this an philosophical discussion for now.
JavaScript Web Resource Functional Breakdown Structure
It is helpful to look at your JavaScript library from a top down hierarchical perspective. There is more investment up front in taking the time to organize this way because it requires more strategic thinking about the actual implementation but it pays dividend when the time comes to upgrade or maintain the solution code.
1 ->Organization -> 2) Entity -> 3) Form -> 4) Function Area
- Keeps the code organized by functional concern and helps to reduce code duplication.
- Splitting the code into files in this way allows for easier concurrent development in a multi-developer environment. When everything is in a few files then developers have to wait until the file is checked back in by someone else.
- Reduces conceptual complexity by breaking down the functionality by area of concern. How easy is to read a 2 mile long JavaScript file?
- Read the complete post at blogs.c5insight.com/.../CRM-2011-JavaScript-Library-Methodology.aspx
SOFTWARE TECHNOLOGY TIPS
The Xrm.Page Script Library Template is a Microsoft Visual Studio 2010 project that provides JScript IntelliSense and JScript libraries which uses Xrm.Page objects and methods.This template provides JScript IntelliSense completion and method documentation. The latest release of the Microsoft Dynamics SDK (Version 5.0.3) contains Microsoft Dynamics CRM Solution and Visual Studio extension that together will provide IntelliSense support for the Xrm.Page object in form scripts.
|
To install the Xrm.Page JScript Library Project, Microsoft Dynamics SDK (Version 5.0.3) needs to be downloaded. The installation files are available in the files downloaded for the Microsoft Dynamics CRM 2011 SDK at SDK\Templates\Xrm.PageScriptProjectTemplate.
In Visual Studio, select File > New > Project. Now Xrm.Page JScript Library Project template will visible on .NET language option.
To create new JScript library files, must drag the XrmPageTemplate.js file to the top of new JScript library to create the reference that enables Visual Studio IntelliSense. The following reference must appear at the top of the file:
// <reference path="XrmPageTemplate.js" />
Now with this reference anyone can simply start typing "Xrm" which will follow the completion and method documentation which will be provided by JScript IntelliSense.If anyone use the incorrect name, or the incorrect casing, will only see the standard JScript object properties with no IntelliSense method documentation.
|
How to Deploy your API as a web app or API app
Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...
-
I was looking at developer’s toolkit shipped with CRM2011 SDK. There are few blogs out there on how to create plugins using developer's...
-
he usual way of generating quotation document in Microsoft Dynamics CRM is either using a lengthy word mail merge process or by creating...
-
Follow the below steps to download the Tools, Step 1: Create a folder in D Drive and name it as “ Dynamics_365_Development_Tools “ Step 2...