Showing posts with label Web Resource. Show all posts
Showing posts with label Web Resource. Show all posts

Friday, 8 September 2017

Ho to Pass parameters to HTML Web resource inside of MS CRM 2011/2013/2015/2016

HTML web resource page can only accept a single custom parameter called data. To pass more than one value in the data parameter, you need to encode the parameters and decode the parameters in our page.
The example can be found in the SDK folder that can be downloaded freely. The path is sdk\samplecode\js\webresources\showdataparams.htm
First we have to create a HTML web resource(Lets say : ViewDataParams.htm) and call it as below by passing parameters:
http://<server name>/WebResources/new_/ViewDataParams.htm?Data=first%3DFirst%20Value%26second%3DSecond%20Value%26third%3DThird%20Value
Using Data parameter we can pass multiple values to HTML web resource.
On the HTML page we can read the values using JavaScript on page load in below ways:
document.onreadystatechange = function () {
if (document.readyState == “complete”) {
getDataParam();
}
}
function getDataParam() {
//Get the any query string parameters and load them
//into the vals array
var vals = new Array();
if (location.search != “”) {
vals = location.search.substr(1).split(“&”);
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, ” “).split(“=”);
}
//look for the parameter named ‘data’
var found = false;
for (var i in vals) {
if (vals[i][0].toLowerCase() == “data”) {
parseDataValue(vals[i][1]);
found = true;
break;
}
}
if (!found)
{ noParams(); }
}
else {
noParams();
}
}
function parseDataValue(datavalue) {
if (datavalue != “”) {
var vals = new Array();
var message = document.createElement(“p”);
setText(message, “These are the data parameters values that were passed to this page:”);
document.body.appendChild(message);
vals = decodeURIComponent(datavalue).split(“&”);
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, ” “).split(“=”);
}
//Create a table and header using the DOM
var oTable = document.createElement(“table”);
var oTHead = document.createElement(“thead”);
var oTHeadTR = document.createElement(“tr”);
var oTHeadTRTH1 = document.createElement(“th”);
setText(oTHeadTRTH1, “Parameter”);
var oTHeadTRTH2 = document.createElement(“th”);
setText(oTHeadTRTH2, “Value”);
oTHeadTR.appendChild(oTHeadTRTH1);
oTHeadTR.appendChild(oTHeadTRTH2);
oTHead.appendChild(oTHeadTR);
oTable.appendChild(oTHead);
var oTBody = document.createElement(“tbody”);
//Loop through vals and create rows for the table
for (var i in vals) {
var oTRow = document.createElement(“tr”);
var oTRowTD1 = document.createElement(“td”);
setText(oTRowTD1, vals[i][0]);
var oTRowTD2 = document.createElement(“td”);
setText(oTRowTD2, vals[i][1]);
oTRow.appendChild(oTRowTD1);
oTRow.appendChild(oTRowTD2);
oTBody.appendChild(oTRow);
}
oTable.appendChild(oTBody);
document.body.appendChild(oTable);
}
else {
noParams();
}
}
function noParams() {
var message = document.createElement(“p”);
setText(message, “No data parameter was passed to this page”);
document.body.appendChild(message);
}
//Added for cross browser support.
function setText(element, text) {
if (typeof element.innerText != “undefined”) {
element.innerText = text;
}
else {
element.textContent = text;
}
}
An HTML web resource can accept only the parameters in the following table.
ParameterNameDescription
typenameEntity NameThe name of the entity.
typeEntity Type CodeAn integer that uniquely identifies the entity in a specific organization.
idObject GUIDThe GUID that represents a record.
orgnameOrganization NameThe unique name of the organization.
userlcidUser Language CodeThe language code identifier being used by the current user.
orglcidOrganization Language CodeThe language code identifier that represents the base language for the organization.
dataOptional Data ParameterAn optional value that may be passed.
formidForm IdThe GUID that represents a form ID.
entrypointEntry PointA string value. This parameter is intended to be passed as an optional value to web resources opened as custom help content for an entity. When enabled, the custom help URL will include a value of either “form” or “hierarchychart”. More information: Add custom help content



Credit: To whom I follow a great blogger: Sanjaya

How to Open Entity or View using direct CRM URL in MS CRM 2011/2013/2015/2016

We can use URLs to open specific entities and views whenever we requires in our custom applications. The below are the scenarios to open entity forms and views using URLs.
NOTE : Use Xrm.Utility.openEntityForm when you open entity forms programmatically within the application by using web resources. Do not use window.open.Outside the application, where pages do not have access to the Xrm.Utility.openEntityForm function, use window.open or a link to open a specific record or form for an entity.

Open a new Entity Record:


http://crmurl/Org/main.aspx?etn=&pagetype=entityrecord
E.g. : FOR new  contact :  http://crmurl/Org/main.aspx?etn=contact&pagetype=entityrecord

open a contact entity record form where the id is {81330924-802A-4B0D-A900-34FD9D790829}:


http://myorg.crm.dynamics.com/main.aspx?etn=contact&pagetype=entityrecord&id=%7B81330924-802A-4B0D-A900-34FD9D790829%7D

open the Active Contacts view for Microsoft Dynamics 365 (online) with no navigation bar or command bar


http://myorg.crm.dynamics.com/main.aspx?etn=contact&pagetype=entitylist&viewid={00000000-0000-0000-00AA-000010001004}&viewtype=1039&navbar=off&cmdbar=false
Learn deeply: Click Here

Tuesday, 23 February 2016

Opening up the HTML Web Resource from a Javascript

Hi All,

many times we are customizing CRM where we need to create a HTML web resource for some special UI/requirement and need to open using a modal popup.

Now here I am going to show, how can we open HTML Web Resource from a Javascript Function instead (triggered by the click of the Ribbon Button).


This function uses the Xrm.Utility.openWebResource() method introduced in Roll-Up 8  of CRM 2011.


The Function call allows you to specify the web resource URL, and the size of the pop-up window.

Xrm.Utility.openWebResource("new_webResource.htm?typename=account&userlcid=1033", null, 300, 300);


Some extra knowledge with this :)



Cheers,
Jitendra Sahu