+ Start a Discussion
TheLearnerTheLearner 

java script button problem--very urgent


Hi Experts,

Im getting this " Id value a88190000008Qov is not valid for the TWM_PMP_Letter_Information__c standard controller ". could anyone help me please. here TWM JOb is (Parent) TWM_PMP_Letter_Information__c is child( there is lookup relationship). i had created button on the TWM job, when i click on that button its showing error, in the button code from alert('after 21'); code is not working could any one help me please

<apex:page renderAs="pdf" standardController="TWM_PMP_Letter_Information__c">
 <table style="table-layout:fixed; font-family: Arial,Sans-Serif; font-size: 11pt;">
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Name__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Line1_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Line2_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Line3_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Town_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Postcode_of_Mailing_Address__c}</td></tr>  
                                 </table>
                                 </apex:page>
Button code:

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 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+"'");

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  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('Tesing'+relRecords);
var records = relRecords.getArray("records");
var recrdlength = records.length;
alert('after 21');
var recs = relRecords.TWM_PMP_Letter_Information__r.getArray("records");
alert('Tesing length'+recrdlength );
var pmpId = recs[0].Id;

alert('Tesing for twmpmp'+pmpId );

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

alert('Tesing install'+InstallRecords );

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");
Tejpal KumawatTejpal Kumawat
Hello Friend,

Please check, In your page "TWM_Job_NoAcc4_letterPdf" standard controller and Record "a88190000008Qov" object are not same. So please send RecordId of your standard controller object.


If this answers your question mark Best Answer it as solution and then hit Like!
 
TheLearnerTheLearner
Hi Tejpal,

Yes ur right, im not able to give TWM_PMP_Letter_Information__c in the jave script could you tell me how to pass please what ever i written the button its not even opening the pdf, could you please help me out., i created button in TWM JOb object this is parent of TWM_Letter_Information object which is lookup relationship.

<apex:page renderAs="pdf" standardController="TWM_PMP_Letter_Information__c" applyBodyTag="false" showHeader="false" sidebar="false" standardStylesheets="false" applyHtmlTag="false">
    <Head>
        <style type="text/css" media="print">
            @page{                  
                margin-left: 1cm;
                margin-right: 1cm;                 
                margin-top: 0.5cm;
                margin-bottom: 0.75cm;
                             
                          
            }
            @page:first
            {
            
              @top-center{
                    content: element(header);
                }
                
              @bottom-center{
                    content: element(footer);
                }
            }
            
            div.footer {
                display: block;
                padding: 2px;
                position: running(footer);
            }
            
           .pagenumber:before {
                content: counter(page);
            }
            
           .pagecount:before {
                content: counter(pages);
            }   
                     
            .ParagraphText{
               font-family: Arial,Sans-Serif;
               font-size: 10pt;
            }
            
        </style>
    </Head>
    <div class = "Header">
        <div style="float: right;"><apex:image url="{!$Resource.ThamesWaterLogo}"/></div>
    </div>
    <div class="content">
           
             <apex:outputPanel style="display:block">
             <br/><br/><br/><br/><br/><br/>
                     <table style="table-layout:fixed">
                        <tr>
                              <td>
                                <table style="table-layout:fixed; font-family: Arial,Sans-Serif; font-size: 11pt;">
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Name__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Line1_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Line2_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Line3_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Town_of_Mailing_Address__c}</td></tr>
                                  <tr><td colspan="1">&nbsp;{!TWM_PMP_Letter_Information__c.Postcode_of_Mailing_Address__c}</td></tr>  
                                 </table>
                             </td>
                         <td>
                           <table style="table-layout:fixed">
                            <tr>
                                <td align="right"><apex:image url="{!$Resource.ThamesWaterSystem}"/></td>
                                <td><apex:outputLabel style="color: #195E8D;  font-family: Arial,Sans-Serif; font-size: 14px; font-weight: bold;">thameswater.co.uk/mymeter</apex:outputLabel></td>
                            </tr>
                            <tr>
                               <td align="right"><apex:image url="{!$Resource.ThamesWaterCall}" /></td>
                              <td>
                                <table style="table-layout:fixed">
                                <tr>
                                    <td align="left"><apex:outputLabel style="color: #FF0000;  font-family: Arial,Sans-Serif; font-size: 14px; font-weight: bold;">0800 009 3816</apex:outputLabel><br/>
                                    <apex:outputLabel style=" font-family: Arial,Sans-Serif; font-size: 11px; " value="Mon - Fri 8am-8pm, Sat 8am-1pm"></apex:outputLabel></td>
                                </tr>
                              </table>
                              </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><br/><apex:outputLabel style="color: #195E8D;  font-family: Arial,Sans-Serif; font-size: 14px;" value="Job ref: {!TWM_PMP_Letter_Information__c.name}"/></td>
                            </tr>
                            </table>
                           </td>
                        </tr>
                    </table>
                </apex:outputPanel>   
                <br/><br/>
                &nbsp;&nbsp;
               <apex:outputText value="{0,date,dd MMMM yyyy}" style="font-family: Arial,Sans-Serif; font-size: 14px;">
                   <apex:param value="{!TWM_PMP_Letter_Information__c.Letter_1_Actual__c}" />
              </apex:outputText><br/><br/>
              <apex:outputLabel Style="color: #195E8D; font-family: Arial,Sans-Serif; font-size: 20px; font-weight: bold;">Please call us to arrange an appointment</apex:outputLabel>
              <p>
               <apex:outputLabel Styleclass="ParagraphText">Dear {!TWM_PMP_Letter_Information__c.Name__c},<br/><br/>
                Since we first wrote to you about plans to fit water meters in your area, we have had difficulty trying to<br/>
                reach you to arrange an appointment to check the best way of fitting a water meter at your property.<br/><br/>
                
                Could you please contact us as we need an appointment with you so we can identify the most suitable<br/>
                place to fit your meter. Please call <span style="color: #ff0000; font-weight: Bold;">0800 009 3816.</span>
              </apex:outputLabel>  
            </p>            
            <p>
            <apex:outputLabel style="color: #195E8D; font-family: Arial,Sans-Serif; font-size: 10pt; font-weight: Bold;">What will my appointment involve?</apex:outputLabel><br/>
            <apex:outputLabel Styleclass="ParagraphText">We will carry out a quick test that involves asking you to check whether water comes out of your tap<br/>
               after we temporarily turn your supply off. This will ensure your meter will only record your water use<br/>
               and not your neighbours.<br/><br/>
            
               If we find from this test it isn’t possible to fit your meter in the pavement or road then we will see if we<br/>
               can fit the meter under your driveway, garden or inside your home. If we are able, we will try to install<br/>
               the meter during this appointment to minimise disturbance. This should take no more than an hour.</apex:outputLabel>
            </p>
            <p>
            <apex:outputLabel style="color: #195E8D; font-family: Arial,Sans-Serif; font-size: 10pt; font-weight: Bold;" value="Why are you fitting meters?"></apex:outputLabel><br/>
            <apex:outputLabel Styleclass="ParagraphText">Managing water supplies will only get more difficult as our population grows and our climate changes.<br/>
               As a result, we need to modernise the way we manage supplies by fitting meters across our region.<br/><br/>
               
               Meters are the fairest way to pay, as you only pay for what you use, and metered customers tend to<br/>
               use 12 per cent less water. Smart technology will enable you to view your usage online to better<br/>
               control your bill<br/><br/>
               
               We hope to hear from you soon.<br/><br/>
               Yours sincerely,<br/><br/></apex:outputLabel>
               <apex:image url="{!$Resource.Danny_Leamon_Signature}" width="50" height="40"/>
             </p>
             <p>
             <apex:outputLabel Styleclass="ParagraphText">
                Danny Leamon<br/>
                Head of metering
             </apex:outputLabel>   
             </p>      
        
        <div class = "footer" style = "color: #7E7672;  font-family: Arial,Sans-Serif; font-size: 8pt;">Registered address: Thames Water Utilities Limited, Clearwater Court, Vastern Road, Reading RG1 8DB<br/>
        Company number 02366661 Thames Water Utilities Limited is part of the Thames Water Plc group. VAT registration no GB 537-4569-15</div>
    </div>
</apex:page>

Button code:

{!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');
}