• andrson mathew
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
HI Experts,

I have writing code for the button, in that i need to fetch the records for some conditons for that , i wrote two inner queries now i need to pass " TWM_PMP_Letter_Information__r " object id in the window.open to open the page, but im not able to understand how to pass it, could anyone help me please. here TWM JOB is parent object and the button is there in TWM JOB, TWM PMP LETTER INFORMATION IS CHILD there is lookup relation, in my page im simply using  " 
<apex:page renderAs="pdf" standardController="TWM_PMP_Letter_Information__c"  there is no controller.  I wrot code but its not working at all.please help me out guys. thanks in advance


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

if(
'{!$Profile.Name}' == 'System Administrator' ||
'{!$Profile.Name}' == 'TWM Community User' ||
'{!$Profile.Name}' == 'TWM Community User2' ||
'{!$Profile.Name}' == 'PMP Planner' ||
'{!$Profile.Name}' == 'PMP Manager' ||
'{!$Profile.Name}' == 'PMP Administrator' ||
'{!$Profile.Name}' == 'TW PMP Report Manager' ||
'{!$Profile.Name}' == 'TWM Sandbox' ){

var jobId = '{!TWM_Job__c.Id}';
var flag = false;
var relRecords = sforce.connection.query("Select Id,(select Id,Letter_Type__c,Letter_NoAcc4_Actual__c from TWM_PMP_Letter_Information__r where Letter_Type__c = 'A1' and Letter_NoAcc4_Actual__c <> null limit 1 ),(select id, task_status__c from twm_tasks__r where recordtype.name = 'Survey' and Task_Status__c = 'Letter Sent' limit 1) from TWM_Job__c WHERE Id = '"+jobId+"'");
alert('total reocrds.'+ relRecords );
var records = relRecords.getArray("records");
var recrdlength = records.length;
var recs = relRecords.TWM_PMP_Letter_Information__r.getArray("records");
alert('total Twm pmp letter infor.'+ recs);
var pmpId = recs[0].TWM_Job__c.TWM_PMP_Letter_Information__r.Id;
alert('twmpmp id.'+ pmpId );

var InstallRecords = sforce.connection.query(" Select Id,Job__c,recordtype.name from TWM_Tasks__c Where Job__c = '"+jobId+"' and recordtype.name = 'Install'");

var insRec = InstallRecords.getArray("records");
var qryLength = insRec.length;

if(records.length >0){
for(var i=0; i<records.length; i++){
var record = records[i];
if(record.TWM_Tasks__r != null && record.TWM_Tasks__r.size > 0 && qryLength === 0){
flag = true;
}
}
if(flag === true){
window.open("/apex/TWM_Job_NoAcc4_letterPdf?id="+pmpId+"","_blank");

}
else{
window.alert('Sorry! Task criteria do not meet');
}
}
else{
window.alert('Sorry! Property and Requested Customer Number criteria do not meet');
}
}
else{
window.alert('User do not have the required permissions');
}