Monday, 22 April 2019

Fetch Xml query in webapi Javascript Dynamic 365

    try {

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical'                                                              distinct='false'>";
fetchXml += "<entity name='opportunity'>";
fetchXml += "<attribute name='budgetamount' />";
fetchXml += "<attribute name='statuscode' />";
fetchXml += "<attribute name='opportunityid' />";
fetchXml += "<attribute name='name' />";
fetchXml += "<attribute name='createdby' />";
fetchXml += "<attribute name='ss_requesttype' />";
fetchXml += "<order attribute='name' descending='false' />";
fetchXml += "<filter type='and'>";
fetchXml += "<condition attribute='opportunityid' operator='in'>";
for (var i = 0; i < arrayVals.length; i++) {
var oppId = arrayVals[i].replace("{", "").replace("}", "");
fetchXml += "<value uitype='opportunity'>" + oppId + "</value>";
}
fetchXml += "</condition>";
fetchXml += "</filter>";
fetchXml += "</entity>";
fetchXml += "</fetch>";

        var webapiPath = lXrm.Page.context.getClientUrl() + "/api/data/v9.1/opportunities?fetchXml=" + encodeURIComponent(fetchXml);
        var service = new XMLHttpRequest();
        service.open("GET", webapiPath, false);
        service.setRequestHeader("Accept", "application/json");
        service.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        service.setRequestHeader("OData-MaxVersion", "4.0");
        service.setRequestHeader("OData-Version", "4.0");
        service.setRequestHeader("Prefer", "odata.include-annotations=*");
        //service.setRequestHeader("Prefer", "odata.maxpagesize = 3"); this tag isused to retrieve no of //records
        service.send(null);

        if (service.readyState == 4 /* complete */) {
            if (service.status == 201 || service.status == 200) {
                var result = eval('(' + service.responseText + ')');
                if (result.value.length > 0) {
                   
                    for (var i = 0; i < result.value.length; i++) {
                        var opportunityid = result.value[i].opportunityid;
                        var name = result.value[i].name;
                        var budgetamount = result.value[i].budgetamount;
                        var createdby = result.value[i]['_createdby_value@OData.Community.Display.V1.FormattedValue'];
                       
                    }
                   
                }
            }
        }
    } catch (ex) {

    }

Monday, 15 April 2019

Web API request to refresh Rollup field Dynamic 365 through JavaScript

The following JS function is used to refresh Rollup field through webapi fom javascript

function calcRollupField(serverURL,strTargetEntitySetName, strTargetRecordId, strTargetFieldName)
{
    strTargetRecordId = strTargetRecordId.replace("{", "").replace("}", "");
    var req = new XMLHttpRequest();
    req.open("GET", serverURL + "/api/data/v9.0/" +
        "CalculateRollupField(Target=@p1,FieldName=@p2)?" +
        "@p1={'@odata.id':'" + strTargetEntitySetName + "(" + strTargetRecordId + ")'}&" +
        "@p2='" + strTargetFieldName + "'", false);
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.onreadystatechange = function () {
        if (req.readyState === 4) {
            req.onreadystatechange = null;
            if (req.status === 200) {
                var results = JSON.parse(this.response);
            }
            else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify({}));
}

Read only field , get latest value from read only field in in power app portal

Below line is used to make field readonly in power app portal through js $( "#bdo_relationshiprole_name" ).parent().css( "po...