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
sfdc dev 2264sfdc dev 2264 

javascript button click help needed

Hi,

I need help on the following req

1) I am having an opportunity record which is getting created automatically from case object
2) I am having another button where i am trying to create a new proposal object record auomatically from opportunity which is master object through a button click on opporunity

I have written a javascript on button click , but its not working

Below is my code
 
MY JAVASCRIPT CODE


{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')} 

var newproposal = new sforce.SObject('Proposal__c'); 
newproposal.Opportunity__c ='{!Opportunity.Id}'; 
newproposal.Account__c	= '{!Case.AccountId}'; 
newproposal.Name = '{!Opportunity.Name}'; 
newproposal.Status__c= 'ENG approved'; 
newproposal.Proposal_Start_Date__c = new Date(); 
newproposal.Proposal_End_Date__c = new Date(); 
newproposal.RecordTypeId='012O0000000DE3V'; 


var result = sforce.connection.create([newproposal]); 

if(result[0].success=='true'){ 
alert('The Proposal record has been Created Successfully.'); 
window.location = '/' + result[0].id; 
}
 Kindly help me on this pls

Thanks in Advance
 
Rohit B ☁Rohit B ☁
Hi!
Your code looks good. Could you please tell me if you are getting any error or is there any required field on the Proposal__c object which you are not specifying here.
sfdc dev 2264sfdc dev 2264
I am not getting error , using all mandatory fields as well , not sure why its not working
Rohit B ☁Rohit B ☁
On which object you are having this button?
sfdc dev 2264sfdc dev 2264
on opportunity object
Rohit B ☁Rohit B ☁
then this below line seems wrong
newproposal.Account__c = '{!Case.AccountId}';
it should be something like this
newproposal.Account__c = '{!Opportunity.AccountId}';
Check if it helps :)
sfdc dev 2264sfdc dev 2264
i tried that too , its not working either v:(
Hemant_JainHemant_Jain
Hello, Can you put the below line to check what the result is
alert('result' +result);
Place the line just above the if conditon :if(result[0].success=='true')
 
Amit Singh 1Amit Singh 1
Use below code.
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')} 

var newproposal = new sforce.SObject('Proposal__c'); 
newproposal.Opportunity__c ='{!Opportunity.Id}'; 
newproposal.Account__c	= '{!Opportunity.AccountId}'; 
newproposal.Name = '{!Opportunity.Name}'; 
newproposal.Status__c= 'ENG approved'; 
newproposal.Proposal_Start_Date__c = new Date(); 
newproposal.Proposal_End_Date__c = new Date(); 
newproposal.RecordTypeId='012O0000000DE3V'; 
var result = sforce.connection.create([newproposal]); 
alert(result);
if(result[0].getBoolean("success") == "true"){ 
     alert("The Proposal record has been Created Successfully."); 
     window.location = '/' + result[0].id; 
}
Also, make sure that there is recordType for Proposal record with "012O0000000DE3V" record Id.

Let me know if this helps :)

Thanks!
Amit Singh