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
sfadm sfadmsfadm sfadm 

Issue when using JSENCODE

When I use the JSENCODE I have the following issue:
var accRegNumber = "{!Account.Registration_Number__c}";
var accName = "{!Account.Name}";
var accType = "{!Account.Custom_Filed_Type__c}";
var accRate = "{!Account.Custom_Filed_Rate__c}";
var accId = "{!Account.Id}";

accRegNumber = {!JSENCODE(accRegNumber)};
accName = {!JSENCODE(accName)};
accType = {!JSENCODE(accType)};
accRate = {!JSENCODE(accRate)};
accId = {!JSENCODE(accId)};
Error: Field accRegNumber does not exist. Check spelling.

Could you please advise why adding {!JSENCODE(accRegNumber)}; to accRegNumber variable is giving an error message?
Amit Chaudhary 8Amit Chaudhary 8
can you try like this

var accRegNumber1 = JSON.parse("{!JSENCODE(accRegNumber )}");
 
Raj VakatiRaj Vakati
Refer this 
 
var accRegNumber = JSON.parse("{!JSENCODE({!Account.Registration_Number__c})}");
var accName = JSON.parse("{!JSENCODE({!Account.Name})}");
var accType = JSON.parse("{!JSENCODE({!Account.Custom_Filed_Type__c})}");
var accRate = JSON.parse("{!JSENCODE({!Account.Custom_Filed_Rate__c})}");
 var accId = JSON.parse("{!JSENCODE({!Account.Id})}");