Search This Blog

Monday, September 21, 2015

Retrieve record from related entity using XrmServiceToolkit javascript in crm 2013/2015

Download XrmServiceToolkit from here
Extract and upload these files into CRM as javascript webresource and also Add on the form where you need to retrieve
1. Json2
2. jquery
3. XrmServiceToolkit

Code: In this code i retrieve description field from related entity

function get_details()
{
var Courselookup=null;
var coursetitle_name=null;
var CourselookupId=null;

 Courselookup = Xrm.Page.data.entity.attributes.get('new_school');
    if (Courselookup.getValue() != null)
    {   
        CourselookupId = Courselookup.getValue()[0].id;   
        var course_obj = Retrieve(CourselookupId);
        if (course_obj.new_Description != null )
        {
            coursetitle_name=course_obj.new_Description;
            Xrm.Page.getAttribute("new_description").setValue(coursetitle_name);
            Xrm.Page.getAttribute("new_description").setSubmitMode("always");
        }
        }
}
function Retrieve(_id) {
    var re;   
    XrmServiceToolkit.Rest.Retrieve(
              _id,
              "new_schoolSet",
              null, null,
              function (result) {
                  re = result;                
              },
              function (error) {
                  alert("failed");
              },
              false
          );
          return re;
}



No comments:

Post a Comment