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
sunny198218sunny198218 

Access custom setting in javascript on VF Page

I have a VF Page where i'm trying to access custom setting in javascript and based on that custom setting, i'm trying to redirect the page to another Page. I have 2 issues here

 

1. I need this javascript to execute on page load. Currently the onload function written on body does not works.

 

2. If i click on button then onclick event does works and i only get an alert of "Hi" and nothng else so i believe it is not accessing custom setting in javascript. 

 

<apex:page id="Page" >

<script type="text/javascript">

function CheckLocking()
{
alert("Hi");
var originalbaseURL = baseURL;
var blockChanges = "{!$Setup.MaintenanceWindow__c.Block__c}";
alert("ok");
alert(blockChanges);
// Following is the url of Custom Lookup page. You need to change that accordingly
baseURL = "/apex/MaintenancePage";

if(blockChanges== 'Yes')
{
openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=yes,resizable=yes,scrollable=yes", true);
}
}
</script>
<apex:form id="myForm">
<body onload="CheckLocking()">
</body>
<apex:commandButton value="click me" onclick="CheckLocking()"/>
<apex:outputText value="{!$Setup.MaintenanceWindow__c.Block__c}"/>


</apex:form>
</apex:page>

nbknbk

Can you use the script tag code in bottom of the page.

 

<apex:page>

<apex:form id="myForm">
<apex:commandButton value="click me" onclick="CheckLocking()"/>
<apex:outputText value="{!$Setup.MaintenanceWindow__c.Block__c}"/>

</apex:form>

<script type="text/javascript">

function CheckLocking()
{
alert("Hi");
var originalbaseURL = baseURL;
var blockChanges = "{!$Setup.MaintenanceWindow__c.Block__c}";
alert("ok");
alert(blockChanges);
// Following is the url of Custom Lookup page. You need to change that accordingly
baseURL = "/apex/MaintenancePage";

if(blockChanges== 'Yes')
{
openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,d

irectories=no,menubar=yes,resizable=yes,scrollable=yes", true);
}
}

</script>
</apex:page>