You need to sign in to do that
Don't have an account?
Problem with Onclick JavaScript
Hi Team,
I have below code in Custom button
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}
var recordTypeName = '{!Account.RecordType}';
var BPRecordId = '';
var theDate = new Date();
var currentYear = theDate.getFullYear();
if(recordTypeName == 'Channel'){
var result = sforce.connection.query("Select r.Id 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' ){
var result = sforce.connection.query("Select r.Id From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Grower' limit 1");
BPRecordId = result.getArray("records")[0].Id;
}
else if(recordTypeName == 'Lawn and Garden'){
var result = sforce.connection.query("Select r.Id From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Lawn and Garden' limit 1");
BPRecordId = result.getArray("records")[0].Id;
}
else if(recordTypeName == 'Influencer'){
var result = sforce.connection.query("Select r.Id 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'+'00N90000004WQVZ'; // this ID is differnect with the production,please chage it after deployment
var AccountName = '{!Account.Name}';
var aid='{!Account.Id}';
result = sforce.connection.query("Select Id, Name From Business_Plan__c where Name = \'" + currentYear + "\' and Account__c = \'{!Account.Id}\' limit 1" ); records = result.getArray("records"); if(records.length > 0){ var prevId = records[0].Id; window.top.location=prevId; } else{ window.top.location=BPUrlForNew+'?'+CFID+'='+AccountName+'&'+CFID+'_lkid='
This is not working for lawn and Garden RecordType.
It is showing following error : result.getArray(...)[0] is undefined. Kindly please help me.
All Answers
else if(recordTypeName == 'Lawn and Garden'){
alert("entered");
var result = sforce.connection.query("Select r.Id From RecordType r where r.SobjectType = 'Business_Plan__c' and r.DeveloperName = 'Lawn and Garden' limit 1");
BPRecordId = result.getArray("records")[0].Id;
}
DeveloperName should not consist of spaces i think
here Lawn and Garden record type DeveloperName should be Lawn_and_Garden