Passing WebResource Data to Update Form Field

Passing WebResource Data to Update CRM Form Field :

Here I am Passing the data  entered in a HtML webresource into a crm form field through WebApi(OData Call). Onclick of submit button in a html , It will updated in the crm form.



First Insert the webresource in a form >Customizations>Entity> Forms> Information >Insert > WebResource



Click on the Lokkup >AddNew > Select Type as HTML as follows



Click on  the Text Editor , Inside the Source paste the following code

<html><head><meta><meta><meta><meta></head><body style="word-wrap: break-word;">
 Enter name: <input type="text" name="fname" id="myText">
 <input type="button" value="Submit" onclick="myFunction()"> 

function myFunction() {
var textdata = document.getElementById("myText").value;
//Directly update the crm field without Odata Call
//window.parent.opener.Xrm.Page.getAttribute("new_test1").setValue(textdata) ;

//or With OdataCall

// new_test1 Schema name of updated fields and new_customs entity SchemaName name
var entity = {};
entity.new_test1= textdata;
var entityname;
var RecordId="{","").replace("}","");

var req = new XMLHttpRequest();"PATCH", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.0/"+entityname+ "s("+RecordId + ")", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
 if (this.readyState === 4) {
 req.onreadystatechange = null;
 if (this.status === 204) {
 //Success - No Return Data - Do Something
 else {


while pasting the html codes to word press, it doesn’t taking the code at script. Please go through the image.

Screenshot (341)

Under RichText look like this


Click on OK > Save > PublishCustomizations

Thats it Will work.. Onclick of submit button data entered in HTML text , It will  Updated in crm.

Crming – Enjoy 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s