Sub Title

Thursday, April 5, 2012

CRM5 Passing Multiple Values to a Web Resource Through the Data Parameter

A Web page (HTML) or Silverlight Web resource page can only accept a single custom parameter called data. To pass more than one value within the data parameter, you need to encode the parameters and decode the parameters within your page.

The page below represents a technique to pass the additional values within a single parameter and then process them within your Web resource.



Sample HTML Web Resource


The HTML code below represents a Web page (HTML) Web resource that includes a script that defines function:

function qs(search_for) {
var query = window.location.search.substring(1);
query = unescape(query);
var parms = query.split('&');
for (var i = 0; i < parms.length; i++) { var pos = parms[i].indexOf('='); if (pos > 0 && search_for == parms[i].substring(0, pos)) {
return parms[i].substring(pos + 1);
}
}
return "";
}

Using this page

For dynamic values generated in code, use the encodeURIComponent method on the parameters. The encoded values should be:

first%3DFirst%20Value%26second%3DSecond%20Value%26third%3DThird%20Value

Open the page passing the encoded parameters as the value of the data parameter:

http:///WebResources/new_/ShowDataParams.htm?Data=first%3DFirst%20Value%26second%3DSecond%20Value%26third%3DThird%20Value

Note

If you have added the Web resource to a form and have pasted the un-encoded parameters into the Custom Parameters(data) field, you can just preview the form.

The new_/ShowDataParams.htm will display a dynamically generated table:


first:: First Value
second:: Second Value
third:: Third Value



No comments:

Post a Comment