function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IanSampsonIanSampson 

Custom button to open Join report passing javascript parameters

Hi

I've created a Join report and need to open it from a custom object (a job) to see related information. You cannot pass parameters to a join report using a simple URL and passing pv0 and pv1 etc.

I've been inspired by the following two great articles:

http://salesforce.stackexchange.com/questions/8723/passing-variables-to-joined-reports
and 
http://www.tgerm.com/2011/04/passing-params-to-reports-salesforce.html

and generated
var url = "/00Ow0000006bRmf"; // report ID, in this instance New Contract Status
var method = "POST";
var idToUse = '{!Job__c.Id}'; // pulls in RecordID 


{ !REQUIRESCRIPT("/soap/ajax/29.0/connection.js") }
{ !REQUIRESCRIPT("/soap/ajax/29.0/apex.js") }

 
var postData = "op=run&runReportJson=%7B%22last_modified_user_id%22%3A%2200520000000joZX%22%2C%22breaks%22%3A%5B%7B%22brkcol%22%3A%22072w00000021Jd4%22%2C%22break%22%3A%22072w00000021Jd4%22%2C%22sortColumn%22%3A%22072w00000021Jd4%22%2C%22brkord%22%3A%22up%22%2C%22breakLevel%22%3A%220%22%2C%22brkdat%22%3A%220%22%7D%2C%7B%22brkcol%22%3A%22072w00000021Jc9%22%2C%22break%22%3A%22072w00000021Jc9%22%2C%22sortColumn%22%3A%22072w00000021Jc9%22%2C%22brkord%22%3A%22up%22%2C%22breakLevel%22%3A%221%22%2C%22brkdat%22%3A%220%22%7D%5D%2C%22colorRanges%22%3A%5B%5D%2C%22currency%22%3A%22GBP%22%2C%22cust_devName%22%3A%22Time_Job_Summary%22%2C%22id%22%3A%2200Ow0000006bRmf%22%2C%22cust_name%22%3A%22Time%3AJob+Summary%22%2C%22last_modified_by%22%3A%22Ian+Sampson%22%2C%22details%22%3A%22no%22%2C%22reportParams%22%3A%5B%7B%22param%22%3A%22block_id_counter%22%2C%22value%22%3A%224%22%7D%5D%2C%22templateKey%22%3A%22070w0000000LIsh%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%5D%2C%22sortdir%22%3A%22down%22%2C%22sideBySide%22%3Afalse%2C%22blocks%22%3A%5B%7B%22templateKey%22%3A%22070w0000000LIsh%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%22072w00000021JdR%22%2C%22072w00000021Jf3%22%2C%22072w00000021JfT%22%2C%22072w00000021JfU%22%2C%22072w00000021Jey%22%5D%2C%22last_modified_user_id%22%3A%22%22%2C%22breaks%22%3A%5B%5D%2C%22sideBySide%22%3Afalse%2C%22sortdir%22%3A%22up%22%2C%22colorRanges%22%3A%5B%5D%2C%22format%22%3A%22t%22%2C%22created_by_user_id%22%3A%2200520000000joZX%22%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%2C%22ctitle%22%3A%22%22%2C%22bgdir%22%3A%222%22%2C%22l%22%3A%221%22%2C%22bg2%22%3A16777215%2C%22csize%22%3A3%2C%22bg1%22%3A16777215%2C%22tfg%22%3A0%2C%22ct%22%3A%22none%22%2C%22sal%22%3Atrue%2C%22chco%22%3Atrue%2C%22chsp%22%3Afalse%2C%22cheh%22%3Afalse%2C%22cp%22%3A%22b%22%2C%22cfsize%22%3A12%2C%22fg%22%3A0%2C%22chst%22%3Afalse%2C%22summaries%22%3A%5B%5D%2C%22chsv%22%3Afalse%2C%22Yman%22%3Afalse%7D%5D%2C%22cust_name%22%3A%22Time+booked+to+cases.%22%2C%22v%22%3A142%2C%22co%22%3A%22yes%22%2C%22last_modified_date%22%3A%22%22%2C%22last_modified_by%22%3A%22%22%2C%22s%22%3A%5B%22072w00000021JfU%22%5D%2C%22details%22%3A%22no%22%2C%22blockId%22%3A%220%22%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22Job__c%22%2C%22blockId%22%3A%22B1%22%7D%2C%22customAggregates%22%3A%5B%5D%2C%22rt%22%3A%22070w0000000LIsh%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%22072w00000021Jc7%22%2C%22pv%22%3A%22"&idToUse&"%22%2C%22pn%22%3A%22eq%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%5D%2C%22reportParams%22%3A%5B%7B%22param%22%3A%22colDt_c%22%2C%22value%22%3A%22072w00000021JcQ%22%7D%2C%7B%22param%22%3A%22colDt_e%22%2C%22value%22%3A%22%22%7D%2C%7B%22param%22%3A%22colDt_q%22%2C%22value%22%3A%22custom%22%7D%2C%7B%22param%22%3A%22colDt_s%22%2C%22value%22%3A%22%22%7D%2C%7B%22param%22%3A%22function%22%2C%22value%22%3A%22c%22%7D%2C%7B%22param%22%3A%22name_op%22%2C%22value%22%3A%22co%22%7D%2C%7B%22param%22%3A%22save_drill%22%2C%22value%22%3A%22true%22%7D%5D%7D%2C%7B%22templateKey%22%3A%22070w0000000LIsm%22%2C%22scope%22%3A%22organization%22%2C%22sort%22%3A%22072w00000021JhW%22%2C%22topn%22%3A0%2C%22last_modified_user_id%22%3A%22%22%2C%22c%22%3A%5B%22072w00000021Jh5%22%2C%22072w00000021JhV%22%2C%22072w00000021JhW%22%2C%22072w00000021Jh0%22%5D%2C%22sideBySide%22%3Afalse%2C%22sortdir%22%3A%22up%22%2C%22breaks%22%3A%5B%5D%2C%22colorRanges%22%3A%5B%5D%2C%22format%22%3A%22t%22%2C%22created_by_user_id%22%3A%2200520000000joZX%22%2C%22cust_name%22%3A%22Time+booked+to+jobs%22%2C%22v%22%3A142%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%2C%22ctitle%22%3A%22%22%2C%22bgdir%22%3A%222%22%2C%22l%22%3A%221%22%2C%22bg2%22%3A16777215%2C%22csize%22%3A3%2C%22bg1%22%3A16777215%2C%22tfg%22%3A0%2C%22ct%22%3A%22none%22%2C%22sal%22%3Atrue%2C%22chco%22%3Atrue%2C%22chsp%22%3Afalse%2C%22cheh%22%3Afalse%2C%22cp%22%3A%22b%22%2C%22cfsize%22%3A12%2C%22fg%22%3A0%2C%22chst%22%3Afalse%2C%22summaries%22%3A%5B%5D%2C%22chsv%22%3Afalse%2C%22Yman%22%3Afalse%7D%5D%2C%22last_modified_date%22%3A%22%22%2C%22co%22%3A%22yes%22%2C%22last_modified_by%22%3A%22%22%2C%22details%22%3A%22no%22%2C%22s%22%3A%5B%22072w00000021JhW%22%5D%2C%22blockId%22%3A%221%22%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22Job__c%22%2C%22blockId%22%3A%22B0%22%2C%22csfReferences%22%3A%5B%22FORMULA1%22%2C%22FORMULA2%22%2C%22FORMULA3%22%5D%7D%2C%22customAggregates%22%3A%5B%5D%2C%22rt%22%3A%22070w0000000LIsm%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%22072w00000021Jfb%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22"&idToUse&"%22%7D%5D%2C%22reportParams%22%3A%5B%7B%22param%22%3A%22colDt_c%22%2C%22value%22%3A%22072w00000021Jfu%22%7D%2C%7B%22param%22%3A%22colDt_e%22%2C%22value%22%3A%22%22%7D%2C%7B%22param%22%3A%22colDt_q%22%2C%22value%22%3A%22custom%22%7D%2C%7B%22param%22%3A%22colDt_s%22%2C%22value%22%3A%22%22%7D%2C%7B%22param%22%3A%22function%22%2C%22value%22%3A%22c%22%7D%2C%7B%22param%22%3A%22name_op%22%2C%22value%22%3A%22co%22%7D%5D%7D%5D%2C%22format%22%3A%22mb%22%2C%22created_by_user_id%22%3A%2200520000000joZX%22%2C%22v%22%3A142%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%2C%22ctitle%22%3A%22%22%2C%22bgdir%22%3A%222%22%2C%22l%22%3A%221%22%2C%22bg2%22%3A16777215%2C%22csize%22%3A3%2C%22bg1%22%3A16777215%2C%22tfg%22%3A0%2C%22ct%22%3A%22none%22%2C%22sal%22%3Atrue%2C%22chco%22%3Atrue%2C%22chsp%22%3Afalse%2C%22cheh%22%3Afalse%2C%22cp%22%3A%22b%22%2C%22cfsize%22%3A12%2C%22fg%22%3A0%2C%22chst%22%3Afalse%2C%22summaries%22%3A%5B%5D%2C%22chsv%22%3Afalse%2C%22Yman%22%3Afalse%7D%5D%2C%22last_modified_date%22%3A%221%2F05%2F2015+5%3A33+PM%22%2C%22co%22%3A%22yes%22%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22Job__c%22%7D%2C%22customAggregates%22%3A%5B%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B0%23Activity.Hours__c%3ASUM%2BB1%23Activity.Hours__c%3ASUM%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22RowBreakContext%22%3A%22072w00000021Jc9%22%2C%22DeveloperName%22%3A%22FORMULA1%22%2C%22MasterLabel%22%3A%22Total+Hours%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B0%23Job__c.Budget_hours__c%3AAVG%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22RowBreakContext%22%3A%22072w00000021Jc9%22%2C%22DeveloperName%22%3A%22FORMULA2%22%2C%22MasterLabel%22%3A%22Budget%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B0%23Job__c.Budget_hours__c%3ASUM-B1%23Activity.Hours__c%3ASUM-B0%23Activity.Hours__c%3ASUM%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22RowBreakContext%22%3A%22072w00000021Jc9%22%2C%22DeveloperName%22%3A%22FORMULA3%22%2C%22MasterLabel%22%3A%22Remaining+Hours%22%2C%22Scale%22%3A2%7D%5D%2C%22rt%22%3A%22070w0000000LIsh%22%2C%22cust_owner%22%3A%2200lw0000002O9ru%22%7D";

    // You REALLY want async = true.
    // Otherwise, it'll block ALL execution waiting for server response.
    var async = true;

    var request = new XMLHttpRequest();

    // Before we send anything, we first have to say what we will do when the
    // server responds. This seems backwards (say how we'll respond before we send
    // the request? huh?), but that's how Javascript works.
    // This function attached to the XMLHttpRequest "onload" property specifies how
    // the HTTP response will be handled.
    request.onload = function() {

   //     var stateObj = { foo: "+ 00Ow0000006bRmf" };
   //     history.pushState(stateObj, "page 2", "+ 00Ow0000006bRmf");

        var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
        var data = request.responseText; // Returned data, e.g., an HTML document.
        var x = window.open("", "_self", "", "false").document;
        x.open();
        x.write(data);
        x.close();

    } // END open window var

    request.open(method, url, async);


    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    // Or... request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
    // Or... whatever

    // Actually sends the request to the server.
    request.send(postData);
} // ONLOAD

But when I click the button on my Salesforce object I get  an error saying "Unexpected Token".

Any advice much appreciated.

Cheers
Ian