|
|||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionIn this article, I will see how to you can access a web page with JavaScript code in Microsoft Dynamics CRM. You can process about CRM entities or different action in that page. In sample JavaScript code; we will take Guid of on Product and we will pass this Guid to If you want cancel the save process of CRM after this error, you must add event.returnValue = false; code block after error code.If there is a value in object that passed a area for show to user. You will find the c# code after JavaScript code. Using the JavaScript CodeThis code will show how to you will access a web page with JavaScript (I will continue to article on JavaScript Code); var oProduct = document.crmForm.all.productid;
// we passed the Lookup object for access to Guid
var aProduct = new Array();
//The lookup is an array on CRM Form. So we must access to
//this objects of array with an array object.
aProduct = oProduct .DataValue;
//Yeah, we found the Guid of Product
var sProductID = aProduct [0].id;sProductID = encodeURIComponent(sProductID);
if (sProductID!=null)
{
//We create an Microsoft.XMLDOM object
var oXmlDoc = new ActiveXObject('Microsoft.XMLDOM');
oXmlDoc.async = false; // we don't want asenkron code process
var path = '/QuoteCalcs/Calcs.aspx?productid=' + sProductID ;
//we passed the path of our web page to XMLDOM object
oXmlDoc.load(path);
//we look for <baris> xml tag - Baris is my name:-)
var oNode = oXmlDoc.selectSingleNode('baris');
if (oNode != null && oNode.text == 'false')
{
alert('an error');
}
if (oNode != null && oNode.text != 'false')
{
//we set value to price area in CRM Form
crmForm.all.price.value = oNode.text;
}
}
Using the c# Script CodeThe real process will run on this aspx page. We takes the parameters that passed from our JavaScriptCode. We are looking for that parameters are empty. Later, We access to CRM Web Services with default credential. If you aren't same domain with Microsoft Dynamics CRM you didn't access to CRM Web Service with default credential so you must access to Web Services with username and password. We will send a query that like select * from filteredproduct where productid=ProductId
with using web services. The response from web services is a BussinessEntityCollection that is the base of all entities in Microsoft Dynamics CRM. We convert the BussinessEntityCollection class to product class. and we are find our value what you want and we return the this value in <baris> xml tag, <%@ Page Language="'c#'%">
<%@ Import Namespace='CrmSdk' %>
<script runat="'server'">
protected override void Render(HtmlTextWriter writer)
{
Response.Clear();
Response.ContentType = 'text/xml';
string ProductID = Request.QueryString['ProductID'];
string TYPE = Request.QueryString['Type'];
if (ProductID != null &&
ProductID !='null')
{
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
QueryByAttribute attributeQuery = new QueryByAttribute();
attributeQuery.ColumnSet = new AllColumns();
attributeQuery.Attributes = new string [] {'productid'};
attributeQuery.Values = new string [] {ProductID};
attributeQuery.EntityName = EntityName.product.ToString();
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = attributeQuery;
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
if (retrieved.BusinessEntityCollection.BusinessEntities.Length > 0)
{
product prd = (product)retrieved.BusinessEntityCollection.BusinessEntities[0];
if (prd.price!=null)
{
Response.Write('<baris>'+prd.price.Value.ToString()+'</baris>');
}
else
{
Response.Write('<baris>false</baris>');
}
}
else
{
Response.Write('<baris>false</baris>');
}
}
}
</script>
All of this process, we have a JavaScript and a c#Script code. In c#Script code we import the CrmSdk dll to the page with import method. You can make your CrmSdk ( Microsoft.Crm.Sdk.Wsdl.dll ) dll. In below you can find how to make your CrmSdk dll. All of those process we must put our code to a server and we must create a virtual directory in CRM Web Site in IIS.
Baris KANLICA
|
||||||||||||||||||||||||||||||||||||||||||||