Add the Dynamic values inside option set through java script in Dynamics 365.

ADD DYNAMIC VALUES IN OPTIONSET

We have a scenario Contact Entity, Test is custom entity. Contact entity has fields like full name and Test entity like contact(option set) is null. We should fill the full name values inside the option set in custom entity. We have approached with ODATA service shown below.

Get contact "fullname" into test entity contact option set field through odata services.

function getcontact()
{
debugger;
//get the contact entity data
var oDataUri = Xrm.Page.context.getClientUrl() +"/xrmservices/2011/OrganizationData.svc/ContactSet?$select=YomiFullName";
      alert(oDataUri);
$.ajax({
type: "GET",
            async: false,
contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataUri,
            beforeSend: function (XMLHttpRequest) {XMLHttpRequest.setRequestHeader("Accept", "application/json");},
            success: function (data, textStatus, XmlHttpRequest) {
alert(data.d.results.length);
//data.d.results.length counts the contact entity total records.
            var i;
for(i=0; i<data.d.results.length; i++)
{
var child= data.d.results[i].YomiFullName;
    Xrm.Page.getControl("new_contact").addOption({value:i , text : child});
            }
           },
            error: function (XMLHttpRequest, textStatus, errorThrown) { alert("error call"); }
        });
}



By using ODATA Services in java script we can achieve only 50 records. if you want to retrieve more than 50 records through ODATA Services use below code.

relatedContact = [];

 if (data && data.d != null && data.d.results != null) {
                Accept(data.d.results);
                fetch(data.d);
            }


function Accept(records) {
    for (var i = 0; i < records.length; i++) {
        relatedContact.push(records[i]);
    }
}

function fetch(records) {
    if (records._next != null) {
        var url = records._next;
        GetRecords(url);
    }
}



2 comments:

  1. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. 作业代写

    ReplyDelete