Thursday 7 February 2013

Run Reports of a particular record in CRM 2011 using javacript



Open particular record and Click run report and select which report you want to run.




Copy the URL on the report window. Use that url on the given code.

function openreport(id) { //  Get Current record Id

    var errorMessage = "Context is not available.";
    var context;
    if (typeof GetGlobalContext != "undefined") {
        context = GetGlobalContext();
    }
    else {
        if (typeof Xrm != "undefined") {

            context = Xrm.Page.context;
        }
        else {
            alert(errorMessage);
            return;
        }
    }

    var orgUrl = context.getServerUrl();

    var reportUrl = orgUrl + "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=OrderAcknowledgement.rdl&id=%7b20a4c6e9-8f6f-e211-957a-00155d000b45%7d&records=" + encodeURIComponent(id) + "&recordstype=10006";

    window.open(reportUrl);

}

Add the Code on CRM webresources and call this method on your ribbon custom button.

No comments:

Post a Comment