Showing posts with label childrecord value in crm. Show all posts
Showing posts with label childrecord value in crm. Show all posts

Wednesday, June 8, 2016

Fetch Child records in MS CRM

function fetchChildRecord() {
    var GUIDvalue = Xrm.Page.data.entity.getId();
    if (GUIDvalue != null) {
        //alert(GUIDvalue);
        var childRec = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                            "<entity name='contact'>" +
                            " <attribute name='fullname' />" +
                            " <attribute name='parentcustomerid' />" +
                            " <attribute name='telephone1' />" +
                            " <order attribute='fullname' descending='false' />" +
                            " <filter type='and'>" +
                            " <condition attribute='parentcustomerid' operator='eq'  value='" + GUIDvalue + "' />" +
                            " </filter>" +
                            "</entity>" +
                            "</fetch> ";

        var childRecords = XrmServiceToolkit.Soap.Fetch(childRec);
        if (childRecords.length > 0) {
            if (childRecords[0].attributes.status != undefined) {
                var StatusValue = childRecords[0].attributes.fullname.value;
                alert(childRecords[0].attributes.fullname.value);
                //return StatusValue;
            }
        }
    }
}

//Have to add the XrmServiceToolkit.js file 
//links to download the file xrmservicetoolkit/xrmservicetoolkit