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();
}
}
if (document.readyState == “complete”) {
getDataParam();
}
}
function getDataParam() {
//Get the any query string parameters and load them
//into the vals array
//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();
}
}
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();
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);
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(“=”);
}
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]);
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);
}
oTRow.appendChild(oTRowTD2);
oTBody.appendChild(oTRow);
}
oTable.appendChild(oTBody);
document.body.appendChild(oTable);
}
else {
noParams();
}
}
document.body.appendChild(oTable);
}
else {
noParams();
}
}
function noParams() {
var message = document.createElement(“p”);
setText(message, “No data parameter was passed to this page”);
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;
}
}
//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.
Parameter | Name | Description |
---|---|---|
typename | Entity Name | The name of the entity. |
type | Entity Type Code | An integer that uniquely identifies the entity in a specific organization. |
id | Object GUID | The GUID that represents a record. |
orgname | Organization Name | The unique name of the organization. |
userlcid | User Language Code | The language code identifier being used by the current user. |
orglcid | Organization Language Code | The language code identifier that represents the base language for the organization. |
data | Optional Data Parameter | An optional value that may be passed. |
formid | Form Id | The GUID that represents a form ID. |
entrypoint | Entry Point | A 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
No comments:
Post a Comment