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
Shannon Andreas 1Shannon Andreas 1 

URL list button hack...not bringing over Account Name and Opportunity Name from Quote to Contract

Trying to create a custom list button, "Generate Contract" that will pre-populate fields from the Quote object to the Contract object through URL. I can get everything to pass except for the lookup fields: Opportunity Name and Account Name.

I have tried this 100 different ways! Here is what I have now for the custom button created on the contract and placed on a related list in the quote::

/800/e?ctrc7={!Opportunity.AccountId}&
CF00NS0000001SGhG={!Opportunity.Id}&
retURL={!Quote.Id}

Here is the result:

https://cs1.salesforce.com/800/e?ctrc7=&CF00NS0000001SGhG=&retURL=0Q0S0000000Dw8F

Just in case anyone is wondering, I did not use the account name and opportunity listed on the Quote because I cannot find the field names when I "view source". I think that I read somewhere that is because those fields are pulled from the opportunity. So I have tried both the Opportunity and Account IDs, Names, etc.

Please help! I have been working on this for weeks and no one seems to be able to help.

Thanks in advance,

Shannon
 
Best Answer chosen by Shannon Andreas 1
Shannon Andreas 1Shannon Andreas 1
Okay! We have a winner! Here is the script that works:

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

var url = '/800/e?' 

var myquery = "Select Id, Account.Id, Account.Name, Opportunity.Id, Opportunity.Name, Service_Effective_Date__c, Contract_Term__c, Total_Contract_Value__c from Quote WHERE Id = '{!Quote.Id}' limit 1"; 
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
var quoteOpportunity = records[0]; 
url += 'ctrc7=' + quoteOpportunity.Account.Name; 
url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Name; 
url += '&ctrc5=' + quoteOpportunity.Service_Effective_Date__c; 
url += '&ctrc40=' + quoteOpportunity.Contract_Term__c; 
url += '&00N3000000B9WLE=' + quoteOpportunity.Total_Contract_Value__c; 

url += '&retURL={!Quote.Id}'; 
window.parent.open(url, "_self");

There was something in the "var myquery" verbiage that it didn't like. Maybe an extra "hidden" character or something. So I just copied and pasted the original verbiage and added each field manually as I added them to the code. Also had to change some of the CF id's to the standard id's ctrc 5 and ctrc 40. Also, I had the wrong id from the last one.

Only problem now is the service effective date is copying over in the wrong format: 2015-08-15 vs 08/15/2015. Really strange as it appears on the form correctly on the Quote. The data types are the same as well.

Thanks Neetu. I appreciate you sticking with me on this!! I will use this code for future scripts and hopefully learn how to create them on my own!

Shannon

All Answers

Neetu_BansalNeetu_Bansal
Hi Shannon,

Please change the behaviour of custom button and select 'Exceute Javascript'. Paste the below code and it will work:

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

var url = '/800/e?'

var myquery = "Select Id, Account.Id, Account.Name, Opportunity.Id from Quote WHERE Id = '{!Quote.Id}' limit 1";
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
     var quoteOpportunity = records[0]; 
     url += 'ctrc7=' + quoteOpportunity.Account.Name;
     url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Id;
}
url += '&retURL={!Quote.Id}';
window.parent.open(url, "_self");

Please mark this as answer if it helps, so it will help others also.

Thanks,
Neetu
Shannon Andreas 1Shannon Andreas 1
Neetu,

Thanks so much for responding!

It works, however, it is pasting the Opportunity Id as is and not the actual name of the opportunity:

https://cs1.salesforce.com/800/e?ctrc7=Test%20phone%20number%20acct%202&CF00NS0000001SGhG=006S0000008zmQLIAY&retURL=0Q0S0000000Dw8F

I tried changing the oppty line on the code to:


url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Name;

Also tried:

but it came back with an entry "undefined".

url += '&CF00NS0000001SGhG_lkid=' + quoteOpportunity.Opportunity.Id;

but nothing appeared.


Thanks again for your response! 

BTW, I knew I needed javascript and went down that road on another post. I kind of understand it when I see it, but to create it always seems a challenge! I would like to know how to do this as I don't like working with complex URL hacks. 

Shannon
 
Neetu_BansalNeetu_Bansal
Hi Shannon,

Please use this:


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

var url = '/800/e?'

var myquery = "Select Id, Account.Id, Account.Name, Opportunity.Id, Opportunity.Name from Quote WHERE Id = '{!Quote.Id}' limit 1";
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
     var quoteOpportunity = records[0]; 
     url += 'ctrc7=' + quoteOpportunity.Account.Name;
     url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Name;
}
url += '&retURL={!Quote.Id}';
window.parent.open(url, "_self");

Please mark this as answer if it helps, so it will help others also.

Thanks,
Neetu
 
Shannon Andreas 1Shannon Andreas 1
Neetu, it worked!! Thank you very much. Now...

I want to add some other fields to the code...all are custom fields on Quote to custom and standard fields on Contract.

Quote field: Service_Effective_Date__c to Contract field: StartDate
Quote field: Contract_Term__c to Contract field: ContractTerm
Quote field: Total_Contract_Value__c to Contract field: Total_Contract_Value__c

Thanks!

Shannon
Neetu_BansalNeetu_Bansal
Hi Shannon,

For populating these fields by default, I will need the id of these fields as for Account and Opportunity, you already provided.

Thanks,
Neetu
Shannon Andreas 1Shannon Andreas 1
Sorry Neetu!


Quote field: Service_Effective_Date__c to Contract field: StartDate
CF00N3000000B8gqG to Contract.StartDate or ctrc5

Quote field: Contract_Term__c to Contract field: ContractTerm
CF00N3000000B8gr4 to Contract.ContractTerm or ctrc15

Quote field: Total_Contract_Value__c to Contract field: Total_Contract_Value__c
CF00NS0000001SDl5 to Contract field: CF00N3000000B9WLE

 
Neetu_BansalNeetu_Bansal
Hi Shannon,

Use this piece of code:

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

var url = '/800/e?'

var myquery = "Select Id, Account.Id, Account.Name, Opportunity.Id, Opportunity.Name,
Service_Effective_Date__c, Contract_Term__c, Total_Contract_Value__c from Quote WHERE Id = '{!Quote.Id}' limit 1";
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
     var quoteOpportunity = records[0]; 
     url += 'ctrc7=' + quoteOpportunity.Account.Name;
     url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Name;
     url += '&CF00N3000000B8gqG=' + quoteOpportunity.Service_Effective_Date__c;
     url += '&CF00N3000000B8gr4=' + quoteOpportunity.Contract_Term__c;
     url += '&CF00NS0000001SDl5=' + quoteOpportunity.Total_Contract_Value__c;
}
url += '&retURL={!Quote.Id}';
window.parent.open(url, "_self");

Please mark this as answer if it helps, so it will help others also.

Thanks,
Neetu
 
Shannon Andreas 1Shannon Andreas 1
Neetu,

Getting an "unterminated string literal" error.
Shannon Andreas 1Shannon Andreas 1
Also, the "from" fields are from the Quote, not oppty.Should I pull this information from the oppty?
Neetu_BansalNeetu_Bansal
Hi Shannon,

There is some javascript error, I might need the data to check the issue.

No I have just use the varible name as 'quoteOpportunity'. You can rename it as 'quoteRec' or anything. And yes, I'm pulling the information from Quote.

Thanks,
Neetu
Shannon Andreas 1Shannon Andreas 1
I am looking for the error. Appears to be right. However, I want to check it against Chrome instead of Firefox. Thought the browser might be the issue.

Will advise.

Thanks,

Shannon
Shannon Andreas 1Shannon Andreas 1
Getting a different error in Chrome:

"Unexpected token ILLEGAL"
Neetu_BansalNeetu_Bansal
Hi Shannon,

Just put one alert of url, before window.open like:

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

var url = '/800/e?'

var myquery = "Select Id, Account.Id, Account.Name, Opportunity.Id, Opportunity.Name,
Service_Effective_Date__c, Contract_Term__c, Total_Contract_Value__c from Quote WHERE Id = '{!Quote.Id}' limit 1";
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
     var quoteOpportunity = records[0]; 
     url += 'ctrc7=' + quoteOpportunity.Account.Name;
     url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Name;
     url += '&CF00N3000000B8gqG=' + quoteOpportunity.Service_Effective_Date__c;
     url += '&CF00N3000000B8gr4=' + quoteOpportunity.Contract_Term__c;
     url += '&CF00NS0000001SDl5=' + quoteOpportunity.Total_Contract_Value__c;
}
url += '&retURL={!Quote.Id}';

alert( url);
window.parent.open(url, "_self");

Give me the url which you get then we can debug the issue.

Thanks,
Neetu
 
Shannon Andreas 1Shannon Andreas 1
Okay! We have a winner! Here is the script that works:

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

var url = '/800/e?' 

var myquery = "Select Id, Account.Id, Account.Name, Opportunity.Id, Opportunity.Name, Service_Effective_Date__c, Contract_Term__c, Total_Contract_Value__c from Quote WHERE Id = '{!Quote.Id}' limit 1"; 
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 

if(records[0]){ 
var quoteOpportunity = records[0]; 
url += 'ctrc7=' + quoteOpportunity.Account.Name; 
url += '&CF00NS0000001SGhG=' + quoteOpportunity.Opportunity.Name; 
url += '&ctrc5=' + quoteOpportunity.Service_Effective_Date__c; 
url += '&ctrc40=' + quoteOpportunity.Contract_Term__c; 
url += '&00N3000000B9WLE=' + quoteOpportunity.Total_Contract_Value__c; 

url += '&retURL={!Quote.Id}'; 
window.parent.open(url, "_self");

There was something in the "var myquery" verbiage that it didn't like. Maybe an extra "hidden" character or something. So I just copied and pasted the original verbiage and added each field manually as I added them to the code. Also had to change some of the CF id's to the standard id's ctrc 5 and ctrc 40. Also, I had the wrong id from the last one.

Only problem now is the service effective date is copying over in the wrong format: 2015-08-15 vs 08/15/2015. Really strange as it appears on the form correctly on the Quote. The data types are the same as well.

Thanks Neetu. I appreciate you sticking with me on this!! I will use this code for future scripts and hopefully learn how to create them on my own!

Shannon
This was selected as the best answer