Search code examples
javascriptjquerydynamics-crmcrmdynamics-crm-2013

CRM 2013 Create an input field in webresource based on optionset field


For my HTML webresource I'm retrieving the value of an optionset field via XrmServiceToolkit.

XrmServiceToolkit.Rest.RetrieveMultiple("tisa_qualitycontrolassessmentSet", "?$select=tisa_questionscore", 
  function(results) {
    for (var i = 0; i < results.length; i++) {
      var tisa_questionscore = results[i].tisa_questionscore;
    }
  }, 
  function(error) {
    Xrm.Utility.alertDialog(error.message);
  }, 
  function() {
    //On Complete - Do Something
  }, 
  false
);

There is no problem. Now I need to add into my HTML page a dropdown input field with the selected value from my query and show a list(dropdown) with the rest of the options of my optionSetValue. The values of the field can be 0 - NO, 1 - Yes and null.

Which is the best practice to create this input field?


Solution

  • If you want to query the particular OptionSet metadata from CRM & populate the values in your HTML dropdown, the below web api can be used to get them. Read more

    https://crmdev.crm.dynamics.com/api/data/v9.1/EntityDefinitions(LogicalName='account')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq 'new_fieldname'&$expand=OptionSet
    

    Edit: I realized later that you're using CRM 2013, so web api won't be available for you. You have to use SDK.Metadata.js like explained in this blog.

    Then from the response, you can iterate & add the <option> to <select> control in HTML like explained in this SO thread