Sometimes we want a simple CRM field to be inserted from web resource page. Let’s make a simplest example by updating Job title field in Contact entity by selecting a value from a dropdown list.

What are our main features in order to achieve the desired functionality?

First we need a name of a form field inside of an entity to be influenced by a variable within a web resource. In our case, name for a Job Title on Contact entity would be ‘jobtitle’. To get the name of any form field we need to visit an entity fields section.

 

YobTitle

 

 

Next step would be to create new or insert an existing web resource to our Contact entity. One of ways to accomplish this is to open a Contact form editor, by opening any contact record from our CRM instance and inside a ribbon of mentioned entity to select a FORM button. Other approach is to open a form editor inside our Default solution, by navigating to Settings/Customization/Customizations and finding a Contact form inside of a section for Customizing the System, as explained in our previous blog post.
In this example we will create an entirely new HTML web resource by navigating to to Settings/Customization/Customizations, and finding Web resources of Default solution. Click on New Web Resource. Write a desired name ( example: JobTitle) and choose a Webpage (HTML) from list. Inside of a Text Editor Source section copy next line of code:

<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Metadata Demonstration</title>
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script type="text/javascript">

function startSample() {
var select = document.getElementById("combobox");
select.onchange = function () {
var index = this.selectedIndex;
var selected = this.options;
var selectedValue= selected[index].text;
window.parent.Xrm.Page.data.entity.attributes.get("jobtitle").setValue(selectedValue);
};
}

</script>
</head>
<body onload="startSample()">
<select id="combobox">
<option value="softwaredeveloper">Softvare Developer</option>
<option value="consultant">Microsoft Dynamics CRM Consultant</option>
<option value="busdeveloper">Business Developer</option>
</select>
</body>
</html>

Click on Save, and then Publish all Customizations. After inserting existing web resource JobTitle.htm on your contact entity by selecting a text value from dropdown list, a Job title field should be populated according to the selection.

dropdown