Reply
Regular Contributor
KNK
Posts: 110
0

OnClick javaScript Button populates existing field values to the current Fields

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}
 
var strength;
var Weakness;
var Threats;
Var Opportuniites;
var recordTypeName = '{!Account.RecordType}';
var AccountName = '{!Account.Name}';
var aid='{!Account.Id}';

if(recordTypeName == 'Channel'){
var result = sforce.connection.query("Select Id Strengths__c, Opportunities__c, Threats__c, Weakness__c From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Distributor' limit 1");
BPRecordId = result.getArray("records")[0].Id;
}
else if(recordTypeName == 'Grower' || recordTypeName == 'Lawn and Garden'){
var result = sforce.connection.query("Select Id Strengths__c, Opportunities__c, Threats__c, Weakness__c From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Grower' limit 1");
BPRecordId = result.getArray("records")[0].Id;
}
else if(recordTypeName == 'Influencer'){
var result = sforce.connection.query("Select Id Strengths__c, Opportunities__c, Threats__c, Weakness__c From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Influencer' limit 1");
BPRecordId = result.getArray("records")[0].Id;
}
else{
alert('Invalid Operation. Please contact System Admin for details!!');
}

var BPDescription = sforce.connection.describeSObject("Business_Plan__c");
var BPUrlForNew = BPDescription.urlNew.split('com')[1];
var CFID = 'CF'+'00NO0000000X9xI'; // this ID is differnect with the production,please chage it after deployment
var AccountName = '{!Account.Name}';
var Strength = '{!Business_Plan__c.Strengths__c}';
var Opportunities = '{!Business_Plan__c.Opportunities__c}';
var Threats = '{!Business_Plan__c.Threats__c}';
var Weakness = '{!Business_Plan__c.Weakness__c}';
var aid='{!Account.Id}';
window.top.location=BPUrlForNew+'?'+CFID+'='+AccountName+'&'+CFID+'_lkid='+aid+'&RecordType='+BPRecordId;

 

 

Hi,

 

 I have created two custom Buttons current year and Next Yeat. If i click on Next Year the field values which has toget auto pouplate to next Year One.

 

 Can any One help me..

Thanks,
Naresh
Regular Contributor
Bharathi Mohan
Posts: 116
0

Re: OnClick javaScript Button populates existing field values to the current Fields

Hi,

 

We can auto-populate the field by passing values via URL,

 

Use the following code,

 

window.top.location=BPUrlForNew+'?'+CFID+'='+AccountName+'&'+CFID+'_lkid='+aid+'&RecordType='+BPRecordId+'&00NU0000000ZGQf='+new Date().getFullYear();

 

We are passing the currecnt year to the Year field.

 

Replace the field id in blue, with your field Id.

You can get your "Year" field Id, by going to the field in the setup, from the URL.

 

 

 

Checkout this link for more details  Salesforce URL to Prepopulate

 

 

Please Mark this post as solved, if it helps you

 

Regards,

Bharathi
Salesforce For All

 

 

 

 

 

Regular Contributor
KNK
Posts: 110
0

Re: OnClick javaScript Button populates existing field values to the current Fields

Not  Only Year Field  I Need some more fileds strength, Weakness, Opportunities and Threats

Thanks,
Naresh
Regular Contributor
Bharathi Mohan
Posts: 116
0

Re: OnClick javaScript Button populates existing field values to the current Fields

Hi KNK,

 

You can pass those fields also in the URL,

 

 

 

Bharathi

Salesforce For All

 

Regular Contributor
KNK
Posts: 110
0

Re: OnClick javaScript Button populates existing field values to the current Fields

Hi Bharathi,

 

I am getting below error message after passing this url in cutom button: window.top.location=BPUrlForNew+'?'+CFID+'='+AccountName+'&'+CFID+'_lkid='+aid+'&RecordType='+BPRecordId+'&'00NO0000000X9xI='+new Date().getFullYear()

 

 

 

 

 

 

 

Thanks,
Naresh
Regular Contributor
Bharathi Mohan
Posts: 116
0

Re: OnClick javaScript Button populates existing field values to the current Fields

Hi,

 

Can you copy and paste the URL in the browser when this page is reached.

 

 

Thanks,

Bharathi

 

Regular Contributor
KNK
Posts: 110
0

Re: OnClick javaScript Button populates existing field values to the current Fields