+ Start a Discussion
Simon WhightSimon Whight 

Javascript to parse fields to Joined Report

Hi,

As a complete Javascript novice, I'm trying to get some assistance here with a script to run a report from a button on the Contracts object that will parse some field data to a joined report. You can't do it with a URL hack, has to be javascript.

Luckily, I have some code to work from, it is rather transparent although I need some help amending it.

My issue is with pulling some information from Salesforce into the script, arrays and such things.
 

Essentially the code I have ripped is looking to parse one field, I am looking to parse two (a custom field from the Accounts object (sagecode__c for arguments sake) and one from the Contracts object itself (contractnumber__c for arguments sake).

This is the code, it is from the author so does not contain anything pertaining to what I am aiming to do in my own org. The header comments are mine.

// JScript source code
// This is a script which parses parameters to a Joined Report as URL hacking will not work in this instance.
// Background reading on solution is here: http://salesforce.stackexchange.com/questions/8723/passing-variables-to-joined-reports
// This script was sourced from here: https://gist.github.com/stephenbrown1/7443749
// Chrome extention tools to debug the report from here: http://forums.chrispederick.com/
// -- -- -- Click FORMS and VIEW FORM INFORMATION to find the reportJson details for this script after running report.
// This site URL encodes the JSON request: http://www.freeformatter.com/url-encoder.html
// Code is annotated where you need to make amendments

var url = "/00O90000004ewmO";    // report ID
var method = "POST";
var idArray = {!GETRECORDIDS($ObjectType.Contract_Partner_vod__c)};   // if the field you want for report critiera isn't avail from the detail record (ie list button) then need to get related data
var idToUse = idArray[0];

//alert(idToUse);

if (idToUse == null) {   // need to have at least 1 record selected
alert('You must select one contract partner record to run this report.');
} else {

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

result = sforce.connection.query("Select Id, Contract_vod__c from Contract_Partner_vod__c where Id = \'" + idToUse + "\'");

var contrId = null;

records = result.getArray("records");

for (var i=0; i< records.length; i++) {
var record = records[i];
contrId = record.Contract_vod__c.substring(0,15);
}

//alert(contrId);

// if the field you want for report critiera isn't avail from the detail record (ie list button) then need to get related data - in this case contract ID

// next line is post data - needs to be URL encoded. Note this is based on what comes from the runReportJson which you can get from running the report and checking firebug
var postData = "op=run&runReportJson=%7B%22last_modified_user_id%22%3A%22005900000022hZg%22%2C%22breaks%22%3A%5B%7B%22brkcol%22%3A%2200N90000007QeT8%22%2C%22break%22%3A%2200N90000007QeT8%22%2C%22sortColumn%22%3A%2200N90000007QeT8%22%2C%22brkord%22%3A%22up%22%2C%22breakLevel%22%3A%220%22%2C%22brkdat%22%3A%220%22%7D%5D%2C%22colorRanges%22%3A%5B%5D%2C%22entity%22%3A%2201I900000018lXc%22%2C%22reln%22%3A%2200N90000007JDQt%22%2C%22currency%22%3A%22000%22%2C%22id%22%3A%2200O90000004ewmO%22%2C%22cust_devName%22%3A%22Contract_Price_List%22%2C%22cust_name%22%3A%22Contract+Price+List%22%2C%22last_modified_by%22%3A%22Paul+Hosking%22%2C%22details%22%3A%22no%22%2C%22reportParams%22%3A%5B%7B%22param%22%3A%22lsk%22%2C%22value%22%3A%221%22%7D%2C%7B%22param%22%3A%22block_id_counter%22%2C%22value%22%3A%226%22%7D%5D%2C%22templateKey%22%3A%2201I900000018lXc00N90000007JDQt%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%2201I900000018lXc00N90000007JDQt%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%22FK_NAME%22%2C%22CUST_NAME%22%2C%2200N90000007QeUH%22%2C%2200N90000007QeT7%22%5D%2C%22last_modified_user_id%22%3A%22%22%2C%22sideBySide%22%3Afalse%2C%22sortdir%22%3A%22up%22%2C%22breaks%22%3A%5B%5D%2C%22a%22%3A%5B%2200N90000007QeT7%22%2C%2200N90000007QeUH%22%5D%2C%22entity%22%3A%2201I900000018lXc%22%2C%22colorRanges%22%3A%5B%5D%2C%22reln%22%3A%2200N90000007JDQt%22%2C%22format%22%3A%22t%22%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%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%22cfsize%22%3A12%2C%22cp%22%3A%22b%22%2C%22cheh%22%3Afalse%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%22v%22%3A142%2C%22cust_name%22%3A%22Contract+Price+Rule%22%2C%22co%22%3A%22no%22%2C%22last_modified_date%22%3A%22%22%2C%22last_modified_by%22%3A%22%22%2C%22details%22%3A%22no%22%2C%22customAggregates%22%3A%5B%5D%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22x%22%2C%22blockId%22%3A%22B1%22%2C%22csfReferences%22%3A%5B%22FORMULA1%22%2C%22FORMULA2%22%2C%22FORMULA3%22%2C%22FORMULA4%22%2C%22FORMULA5%22%2C%22FORMULA6%22%2C%22FORMULA7%22%5D%7D%2C%22rt%22%3A%2251%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%22FK_CUSTENT_ID%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22" + contrId + "%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%2200N90000007QeY2%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%2201I900000018lXc%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%22CUST_NAME%22%2C%2200N90000007QeT6%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%22a%22%3A%5B%2200N90000007QeT6%22%5D%2C%22colorRanges%22%3A%5B%5D%2C%22entity%22%3A%2201I900000018lXc%22%2C%22format%22%3A%22t%22%2C%22v%22%3A142%2C%22cust_name%22%3A%22List+Price%22%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%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%22cfsize%22%3A12%2C%22cp%22%3A%22b%22%2C%22cheh%22%3Afalse%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%22no%22%2C%22last_modified_by%22%3A%22%22%2C%22details%22%3A%22no%22%2C%22customAggregates%22%3A%5B%5D%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22x%22%2C%22blockId%22%3A%22B0%22%7D%2C%22rt%22%3A%2251%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%22CUST_RECORDTYPE%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22List_Price_Rule_vod%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeUG%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeT2%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeT1%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%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%2200N90000007QeY2%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%2C%7B%22templateKey%22%3A%2201I900000018lXc%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%22CUST_NAME%22%2C%2200N90000007QeUH%22%2C%2200N90000007QeT7%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%22entity%22%3A%2201I900000018lXc%22%2C%22format%22%3A%22t%22%2C%22v%22%3A142%2C%22cust_name%22%3A%22STT+Price%22%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%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%22cfsize%22%3A12%2C%22cp%22%3A%22b%22%2C%22cheh%22%3Afalse%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%22no%22%2C%22last_modified_by%22%3A%22%22%2C%22details%22%3A%22no%22%2C%22customAggregates%22%3A%5B%5D%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22x%22%2C%22blockId%22%3A%22B3%22%7D%2C%22rt%22%3A%2251%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%2200N90000007QeT2%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeT1%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007JDQt%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeUG%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeY2%22%2C%22pn%22%3A%22ge%22%2C%22pv%22%3A%22TODAY%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%2200N90000007QeTC%22%2C%22pn%22%3A%22le%22%2C%22pv%22%3A%22TODAY%22%2C%22pc2%22%3A%22%22%2C%22cc%22%3Afalse%7D%2C%7B%22pc%22%3A%22CUST_RECORDTYPE%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22Discount_Rule_vod%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%2200N90000007QeY2%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%22005900000022hZg%22%2C%22charts%22%3A%5B%7B%22ctsize%22%3A18%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%22cfsize%22%3A12%2C%22cp%22%3A%22b%22%2C%22cheh%22%3Afalse%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%22v%22%3A142%2C%22last_modified_date%22%3A%2214%2F11%2F2013+9%3A49+AM%22%2C%22co%22%3A%22yes%22%2C%22customAggregates%22%3A%5B%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22List+Price+List+Price%22%2C%22DeveloperName%22%3A%22FORMULA1%22%2C%22RowBreakContext%22%3A%2200N90000007QeT8%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B3%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22STT+Disc%22%2C%22DeveloperName%22%3A%22FORMULA2%22%2C%22RowBreakContext%22%3A%2200N90000007QeT8%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B3%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22STT+Net%22%2C%22DeveloperName%22%3A%22FORMULA3%22%2C%22RowBreakContext%22%3A%2200N90000007QeT8%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG+-+%28B3%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG+*+B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%29%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22STT+Disc+Net+Price%22%2C%22DeveloperName%22%3A%22FORMULA4%22%2C%22RowBreakContext%22%3A%2200N90000007QeT8%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG+-+%28B1%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG+*+B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%29%22%2C%22DataType%22%3A%22N%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22Contract+Disc+Net+Price%22%2C%22DeveloperName%22%3A%22FORMULA5%22%2C%22RowBreakContext%22%3A%2200N90000007QeT8%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22IF%28B1%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG%3C%3E0%5Cn%2C+B1%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG%5Cn%2C+IF%28B1%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%3C%3E0%5Cn%2C%28B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG+-+B1%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%29+%2F+B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%5Cn%2CIF%28B3%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG%3C%3E0%5Cn%2CB3%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG%5Cn%2CIF%28B3%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%3C%3E0%5Cn%2C+%28B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG+-+B3%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%29%2FB0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%5Cn%2C0%5Cn%29%29%29%29%22%2C%22DataType%22%3A%22P%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22Final+Discount%22%2C%22DeveloperName%22%3A%22FORMULA6%22%2C%22RowBreakContext%22%3A%2200N90000007QeT8%22%2C%22Scale%22%3A2%7D%2C%7B%22IsCrossBlock%22%3Atrue%2C%22CalculatedFormula%22%3A%22IF%28B1%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG+%3C%3E+0%5Cn%2C+B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG+-%28B1%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG+*+B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%29%5Cn%2C+IF%28B1%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG+%3C%3E+0%5Cn%2CB1%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%5Cn%2CIF%28B3%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG+%3C%3E+0%5Cn%2CB0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG+-+%28B3%23Pricing_Rule_vod__c.Discount_Override_vod__c%3AAVG+*B0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%29%5Cn%2CIF%28B3%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG+%3C%3E+0%5Cn%2CB3%23Pricing_Rule_vod__c.Net_Price_vod__c%3AAVG%5Cn%2CB0%23Pricing_Rule_vod__c.List_Price_vod__c%3AAVG%5Cn%29%29%29%29%22%2C%22DataType%22%3A%22C%22%2C%22IsActive%22%3Atrue%2C%22MasterLabel%22%3A%22Final+Net%22%2C%22DeveloperName%22%3A%22FORMULA7%22%2C%22Scale%22%3A2%7D%5D%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22x%22%7D%2C%22rt%22%3A%2251%22%2C%22cust_owner%22%3A%2200D90000000ome4%22%7D&repId=00O90000004ewmO";

// 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 () {

// Because of javascript's fabulous closure concept, the XMLHttpRequest "request"
// object declared above is available in this function even though this function
// executes long after the request is sent and long after this function is
// instantiated. This fact is CRUCIAL to the workings of XHR in ordinary
// applications.

// You can get all kinds of information about the HTTP response.

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().document;
x.open();
x.write(data);
x.close();

}

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);
}
I can see what is going on, array is being created, SoQL query executing, value being stored. But there are some elements I am not sure of:

var idArray = {!GETRECORDIDS($ObjectType.Contract_Partner_vod__c)};   // if the field you want for report critiera isn't avail from the detail record (ie list button) then need to get

Unsure of the syntax I use here. I'm obviously to get ID's from an object to use in a query, I just need to know if I'm going to be formatting it correctly. I would ask our Java guys but I think this falls into the realm of Salesforce syntax.

records = result.getArray("records");

for (var i=0; i< records.length; i++) {
var record = records[i];
contrId = record.Contract_vod__c.substring(0,15);
}

Not sure what this piece of the code is aiming to do either. Is it truncating the 18 character ID? Because if so, I can probably kill this section of code off as I will be purely dealing with strings.



The rest seems relatively straightforward, it looks like I would have to duplicate the code to find my second field to parse. This person is obviously looking for his one custom field to parse to the report, as reflected by the search and result obtained.

Can anyone shed some light here to help me through?

Thanks.
Best Answer chosen by Simon Whight
Simon WhightSimon Whight
Ok, sorted it in the end.

Point 1:

The code there is for when you are using a list button. As I was using a Page Detail Button, I could just refer to the object ID directly.

var idToUse = '{!Contract.Id}';

Point 2

This was pulling the single result from my SoQL results. Vital to use the variable in my parsed URL. So execute SoQL query and write to array, use the FOR loop to get the result you are looking for. Using ALERT(variablename) in my code was vital for me actually seeing what was going on, so use that as a debug.

Once that was sorted, it was indeed a case of getting both variables needed via 2 SoQL queries and dumping into the appropriate place in the parsed URL. All I need now is some error handling for NULL and I'm done.

This works for parsing data from a page to a joined report, so if anybody needs to do this and what I've written isn't transparent, give me a shout.

All Answers

Simon WhightSimon Whight
Ok, sorted it in the end.

Point 1:

The code there is for when you are using a list button. As I was using a Page Detail Button, I could just refer to the object ID directly.

var idToUse = '{!Contract.Id}';

Point 2

This was pulling the single result from my SoQL results. Vital to use the variable in my parsed URL. So execute SoQL query and write to array, use the FOR loop to get the result you are looking for. Using ALERT(variablename) in my code was vital for me actually seeing what was going on, so use that as a debug.

Once that was sorted, it was indeed a case of getting both variables needed via 2 SoQL queries and dumping into the appropriate place in the parsed URL. All I need now is some error handling for NULL and I'm done.

This works for parsing data from a page to a joined report, so if anybody needs to do this and what I've written isn't transparent, give me a shout.
This was selected as the best answer
Simon WhightSimon Whight
Also, change this at the end to make the report open in the same tab and not a new window.

var x = window.open("","_self").document;
x.open();
x.write(data);
x.close();


Nishant Singh PanwarNishant Singh Panwar
Hi Simon,

How are you passing that variable in this whole code and I need to call the report from a command link on VF Page. would be really very helpful if you add some points on that.

Thank You.
Nishant Singh
Simon WhightSimon Whight
Ok. Lines 1 - 8 detail all the sources I went to with finding the tools to make the solution. So make that a first point to stop off at. What you are essentially doing is using a Chrome Extension to decode the JSON when you are running the joined report. The extension tracks it and then you can grab it for use in the code, inserting your own parameters where necessary.

The variables, those are inserted into the huge amount of ridiculous code on line 40. The instructions give you a breakdown on where to find the relevant tools to deconstruct the joined report URL into JSON, which you can then pick through to insert your variables. It is literally a case of finding the part of the JSON which deals with the paramenter, quoting out of the string and adding in the variable.

A bit like:

"stringofJSONcodegoesonandon" + hereisvariable + "stringofJSONcodecontinues"

The issue I had was that I was trying to use an array to find the variable from the Contract object. I didn't need to. I simply referred to the field directly. Check the Best Answer text for that.

For completed purposes, this was my final code. You can see I've chopped a whole load out, no arrays, no SOQL needed. It's literally define variables, call upon jscript, a single validation message, huge amount of JSON, code that pops the report:
 
// JScript source code
// This is a script which parses parameters to a Joined Report as URL hacking will not work in this instance.
// Background reading on solution is here: http://salesforce.stackexchange.com/questions/8723/passing-variables-to-joined-reports
// This script was sourced from here: https://gist.github.com/stephenbrown1/7443749
// Chrome extention tools to debug the report from here: http://forums.chrispederick.com/
// -- -- -- Click FORMS and VIEW FORM INFORMATION to find the reportJson details for this script after running report.
// This site URL encodes the JSON request: http://www.freeformatter.com/url-encoder.html
// Code is annotated where you need to make amendments
// If you need to revert, change this back to a URL content source and replace all of the code with just /00OD0000006I7p4 - doublechecking the behaviour options

var url = "/00OD0000006I7p4"; // report ID, in this instance New Contract Status
var method = "POST";
var idToUse = '{!Contract.Id}'; // pulls in RecordID as this is a Detail Page Button, you can use $GETRECORDIDS and an array for a List Button
var contrId1 = '{!Contract.ContractNumber}';
var contrId2 = '{!Contract.Sage_Id__c}';

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

// REDUNDANT - FIELD EXISTS ON OBJECT, RETAINING FOR REFERENCE - SOQL to pull off the relevant injection field from the array query
{ // this curly bracket is required to comment out the code below
    // result2 = sforce.connection.query("SELECT Sage_Id__c FROM Contract where Id = \'" + idToUse + "\'");
    // records2 = result2.getArray("records");
    //
    // for (var i = 0; i < records2.length; i++) {
    // var record2 = records2[i];
    // if (record2.Sage_Id__c != undefined) {
    // contrId2 = record2.Sage_Id__c.substring(0, 15);
    // } // END IF


    if (contrId2 == "")
        throw new Error("No Sage Number. Make sure this is filled before retrying.");

    // next line is post data - needs to be URL encoded. Note this is based on what comes from the runReportJson which you can get from running the report and checking firebug
    var postData = "op=run&runReportJson=%7B%22last_modified_user_id%22%3A%22005D00000037Qx8%22%2C%22breaks%22%3A%5B%5D%2C%22" +
"colorRanges%22%3A%5B%5D%2C%22currency%22%3A%22000%22%2C%22cust_devName%22%3A%22New_Contract_Summary%22%2C%22id%22%3A%22" +
"00OD0000006I7p4%22%2C%22cust_name%22%3A%22New+Contract+Summary%22%2C%22last_modified_by%22%3A%22Gavin+Nixon%22%2C%22details%22" +
"%3A%22yes%22%2C%22reportParams%22%3A%5B%7B%22param%22%3A%22block_id_counter%22%2C%22value%22%3A%225%22%7D%5D%2C%22templateKey%22" +
"%3A%22ReportAccount%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%5D%2C%22sortdir%22%3A%22down%22%2C%22sideBySide%22%3Afalse%2C%22" +
"blocks%22%3A%5B%7B%22templateKey%22%3A%22ReportAccount%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22" +
"%3A%5B%22ACCOUNT.NAME%22%2C%2200ND0000005u8sz%22%2C%22ADDRESS1_STREET%22%2C%22ADDRESS1_CITY%22%2C%22ADDRESS1_STATE%22%2C%22" +
"ADDRESS1_COUNTRY%22%2C%22ADDRESS1_ZIP%22%2C%22PHONE1%22%2C%22URL%22%2C%22INDUSTRY%22%2C%2200ND0000005sKQ6%22%2C%22EMPLOYEES%22" +
"%2C%2200ND0000005sY6s%22%2C%2200ND0000005sIgr%22%2C%2200ND0000005sIgv%22%2C%2200ND0000005sIgy%22%2C%2200ND0000005sIgw%22" +
"%2C%2200ND0000005uTvL%22%5D%2C%22last_modified_user_id%22%3A%22%22%2C%22sideBySide%22%3Afalse%2C%22sortdir%22%3A%22up%22" +
"%2C%22colorRanges%22%3A%5B%5D%2C%22format%22%3A%22tt%22%2C%22created_by_user_id%22%3A%22005D0000004Hmco%22%2C%22cust_name%22" +
"%3A%22Accounts+block+1%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%22" +
"fg%22%3A0%2C%22chst%22%3Afalse%2C%22summaries%22%3A%5B%5D%2C%22chsv%22%3Afalse%2C%22Yman%22%3Afalse%7D%5D%2C%22co%22%3A%22yes%22" +
"%2C%22last_modified_date%22%3A%22%22%2C%22last_modified_by%22%3A%22%22%2C%22details%22%3A%22yes%22%2C%22blockId%22%3A%220%22" +
"%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22a%22%2C%22blockId%22%3A%22B1%22%2C%22csfReferences%22%3A%5B%5D%7D%2C%22" +
"customAggregates%22%3A%5B%5D%2C%22rt%22%3A%221%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%2200ND0000005tTlI%22%2C%22pv%22%3A%22" + contrId2 +
"%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%22" +
"colDt_c%22%2C%22value%22%3A%22CREATED_DATE%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%22ReportContractList%22%2C%22topn%22" +
"%3A0%2C%22c%22%3A%5B%22CONTRACT_NUMBER%22%2C%22START_DATE%22%2C%22END_DATE%22%2C%22CONTRACT_TERM%22%2C%2200ND0000005tSjK%22" +
"%2C%22STATUS%22%2C%22CUSTOMER_SIGNED_NAME%22%2C%22CUSTOMER_SIGNED_TITLE%22%2C%22CUSTOMER_SIGNED_DATE%22%2C%22" +
"COMPANY_SIGNED_NAME%22%2C%2200ND0000005u0FG%22%2C%2200ND0000005ua7I%22%2C%2200ND0000005tSjF%22%2C%2200ND0000005uTv8%22" +
"%2C%2200ND0000005uTv6%22%2C%2200ND0000005uTv5%22%2C%2200ND0000005uTvD%22%2C%2200ND0000005uTv7%22%2C%2200ND0000005uTvB%22" +
"%2C%2200ND0000005tSjQ%22%2C%2200ND0000005tSjT%22%2C%2200ND0000005tSjR%22%2C%2200ND0000005tSjM%22%2C%2200ND0000005tSjL%22" +
"%2C%2200ND0000005tSjO%22%2C%2200ND0000005tSjN%22%2C%2200ND0000005tSjW%22%2C%2200ND0000005tSjP%22%2C%2200ND0000005tSjU%22" +
"%2C%2200ND0000005tSjS%22%2C%2200ND0000005tSjC%22%2C%2200ND0000005tSjV%22%2C%2200ND0000005tSjX%22%2C%22SPECIAL_TERMS%22%2C%22" +
"00ND0000005uTv3%22%2C%2200ND0000005uTv9%22%2C%2200ND0000005uTv4%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%22" +
"created_by_user_id%22%3A%22005D0000004Hmco%22%2C%22cust_name%22%3A%22Contracts+block+2%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%22" +
"csize%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%22co%22%3A%22yes%22%2C%22last_modified_date%22%3A%22%22%2C%22" +
"last_modified_by%22%3A%22%22%2C%22details%22%3A%22yes%22%2C%22blockId%22%3A%221%22%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22a%22" +
"%2C%22blockId%22%3A%22B0%22%2C%22csfReferences%22%3A%5B%5D%7D%2C%22customAggregates%22%3A%5B%5D%2C%22rt%22%3A%2246%22%2C%22" +
"filters%22%3A%5B%7B%22pc%22%3A%22CONTRACT_NUMBER%22%2C%22pn%22%3A%22eq%22%2C%22pv%22%3A%22" + contrId1 + "%22%7D%5D%2C%22reportParams%22" +
"%3A%5B%7B%22param%22%3A%22colDt_c%22%2C%22value%22%3A%22START_DATE%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%2C%7B%22templateKey%22%3A%22ReportContact%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%22" +
"SALUTATION%22%2C%22FIRST_NAME%22%2C%22LAST_NAME%22%2C%22TITLE%22%2C%22PHONE1%22%2C%22EMAIL%22%2C%2200ND0000005uTze%22%2C%22" +
"00ND0000005uTzd%22%2C%2200ND0000005uTzg%22%2C%2200ND0000005uTzf%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%22" +
"created_by_user_id%22%3A%22005D0000004Hmco%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%22" +
"none%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%22" +
"cust_name%22%3A%22Contacts+%26+Accounts+block+3%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%22details%22%3A%22yes%22%2C%22blockId%22%3A%222%22%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22" +
"a%22%2C%22blockId%22%3A%22B2%22%2C%22csfReferences%22%3A%5B%5D%7D%2C%22customAggregates%22%3A%5B%5D%2C%22rt%22%3A%222%22%2C%22" +
"filters%22%3A%5B%7B%22pc%22%3A%2200ND0000005tTlI%22%2C%22pv%22%3A%22" + contrId2 + "%22%2C%22pn%22%3A%22eq%22%2C%22pc2%22%3A%22%22%2C%22" +
"cc%22%3Afalse%7D%5D%2C%22reportParams%22%3A%5B%7B%22param%22%3A%22colDt_c%22%2C%22value%22%3A%22CREATED_DATE%22%7D%2C%7B%22" +
"param%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%22" +
"param%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%2C%7B%22templateKey%22%3A%22070D0000000PTPc%22%2C%22sort%22%3A%22" +
"072D0000001zenW%22%2C%22scope%22%3A%22organization%22%2C%22topn%22%3A0%2C%22c%22%3A%5B%22072D0000001zenW%22%2C%22" +
"072D0000001zenL%22%2C%22072D0000001zenX%22%2C%22072D0000001zenR%22%2C%22072D0000001zenT%22%2C%22072D0000001zenS%22%2C%22" +
"072D0000001zenV%22%2C%22072D0000001zenU%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%22" +
"005D0000004Hmco%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%22" +
"1%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%22" +
"Accounts+with+Sites+block+4%22%2C%22v%22%3A142%2C%22co%22%3A%22yes%22%2C%22last_modified_date%22%3A%22%22%2C%22" +
"last_modified_by%22%3A%22%22%2C%22details%22%3A%22yes%22%2C%22blockId%22%3A%223%22%2C%22blkInfo%22%3A%7B%22blkjt%22%3A%22" +
"Account%22%2C%22blockId%22%3A%22B3%22%2C%22csfReferences%22%3A%5B%5D%7D%2C%22customAggregates%22%3A%5B%5D%2C%22rt%22%3A%22" +
"070D0000000PTPc%22%2C%22filters%22%3A%5B%7B%22pc%22%3A%22072D0000001zenF%22%2C%22pv%22%3A%22" + contrId2 + "%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%22" +
"072D0000001zemN%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%22" +
"created_by_user_id%22%3A%22005D00000037Qx8%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%22" +
"b%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%2212%2F08%2F2014+11%3A37%22%2C%22co%22%3A%22yes%22%2C%22blkInfo%22%3A%7B%22blkjt%22" +
"%3A%22a%22%7D%2C%22customAggregates%22%3A%5B%5D%2C%22rt%22%3A%221%22%2C%22cust_owner%22%3A%2200lD0000001PgwF%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() {

        // Because of javascript's fabulous closure concept, the XMLHttpRequest "request"
        // object declared above is available in this function even though this function
        // executes long after the request is sent and long after this function is
        // instantiated. This fact is CRUCIAL to the workings of XHR in ordinary
        // applications.

        // You can get all kinds of information about the HTTP response.

        // This pair of lines allows the back button to be used as _self erases the URL from the history.
        //https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

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

        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


Eian AldrichEian Aldrich
I'm struggling to get the variable to inject into the JSON properly as you describe here: 
"stringofJSONcodegoesonandon" + hereisvariable + "stringofJSONcodecontinues"

Mine is just replacing the filter with the text-name of the variable, so clearly it isn't injecting the variable at all. It's just using my JSON string when the button is pressed..

Could you elaborate on this part? I'm unable to find the extension you referenced in the post which I'm assuming makes this easier. This scenario is the exact thing I'm trying to solve currently! 
Simon WhightSimon Whight
It’s been a hefty amount of time since I did this so I’m not so sure how useful I can be. Looks like the extension can be had from here though: http://chrispederick.com/work/web-developer/ It really was a case of going through the ridiculously long string to find the place to insert the variables as declared earlier in the code. I believe the Chrome extension gives you a nice trace of the JSON once you run it normally. Simon Whight CRM Analyst Please direct all Salesforce support queries to salesforcesupport@citation.co.uk as they cannot be answered at this inbox. Registered Office: Kings Court, Water Lane, Wilmslow, Cheshire East, SK9 5AR, United Kingdom. DDI: 0161 667 4168 | T: 0161 667 4000 simonwhight@citation.co.uk | www.citation.co.uk [Citation - Professional Solutions] [cid:image002.jpg@01D0B810.EB6AFFF0]
Eian AldrichEian Aldrich
That was actually helpful, thank you! My issue was I was trying to insert the variable by editing the pre-encoded JSON string and then encoding it. I had to edit the encoded JSON string to get it to work properly. It's sad we have to go to such lengths to get a joined report to be dynamically filtered.... Thanks again!!!
saad mechiche alamisaad mechiche alami
I am getting this error message when the page loads:

The value of the "rt" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

when we look at the "rt" in the postData variable it does not have an ID, why ? the record type is given to me by the runReportJson in the developer tools when i load the report, and its ID is correct and reffers to 2 report type IDs I am using in my joined report.

Anyone faced this issue ?

Thanks