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
KNKKNK 

Onclick java Script donot Prepopulate null Values

Hi,

Can any one help me with the below code, even null values also prepopulating,  I dont want populate null values

 

{!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();
var NextYear =Number(theDate.getFullYear())+1;

if ( '{!User.Profile}' == 'System Administrator' ){
 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' || recordTypeName == 'Lawn and Garden'){
  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 == '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 result =sforce.connection.query("Select Id, Name, Strengths__c, Threats__c, Weakness__c,Opportunities__c From Business_Plan__c where Name = \'" + currentYear + "\' and Account__c = \'{!Account.Id}\' limit 1" );
records = result.getArray("records");
if(records.length > 0 ){
Strength = records[0].Strengths__c;
Opportunity = records[0].Opportunities__c;
Threat = records[0].Threats__c;
Weakness = records[0].Weakness__c;
}

var BPDescription = sforce.connection.describeSObject("Business_Plan__c");
var BPUrlForNew = BPDescription.urlNew.split('com')[1];
var CFID = 'CF'+'00NN0000000KvoM'; // 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 = \'" + NextYear + "\' 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='+aid+'&RecordType='+BPRecordId+'&00NN0000000Kvsi='+Strength+'&00NN0000000KvsV='+Opportunity+'&00NN0000000Kvsl='+Threat+'&00NN0000000Kvsm='+Weakness+'&Name='+NextYear;
}

Janet GuoJanet Guo

In my experience, if a value is null, Salesforce to JS will copy the string "null" out to the UI. I usually have to write code to ensure that the "null" is not getting written to the screen. Like an if JS statement that checks for "null" strings and write out an empty string instead.