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
Raghu_devRaghu_dev 

Disabling/Enabling scontrol based on a conditon

Hi, I need to disable/enable a scontrol (in this case it is a button) based on some logic(if condition). Please let me know how this can be achieved.

Here is the scenario :
We have a "account change queue" object. This object does store all the change requests submitted by reps and the change request transforms through several stages (nothing but status). During some stages, reps are not allowed to do a "request change" (which is a scontrol button) and hence the page should render with a disabled button based on the status field.

The code looks similar to the following..


<script type="text/javascript">
function setupPage() {
sourceId = '{!Queue_Billing_Profile_Change__c.Id}';
var status = '{!Queue_Billing_Profile_Change__c.Billing_Profile_Change_Status__c}';
if (status == "Under Review")
{
// button should be disabled for the above status.
}


</script>




Thanks
TCAdminTCAdmin
Hello Raghu_dev,

It looks like you have the logic to do this. With the auto format I can't be positive because it has the smile.
Code:
<script type="text/javascript">
function setupPage() {
sourceId = '{!Queue_Billing_Profile_Change__c.Id}';
var status = '{!Queue_Billing_Profile_Change__c.Billing_Profile_Change_Status__c}';
if (status == 'Under Review'){
  // button should be disabled for the above status.
} else {
  // Place the button actions within this section
}
</script>

Your other option would be:
Code:
<script type="text/javascript">
function setupPage() {
sourceId = '{!Queue_Billing_Profile_Change__c.Id}';
var status = '{!Queue_Billing_Profile_Change__c.Billing_Profile_Change_Status__c}';
if (status != 'Under Review'){
  // Place the button actions within this section
} else {
  alert('You can not perform this action while Under Review');
}
</script>

 I might have missed something, I have a hard time working with other's code. Please let me know if you have issues with it.


Message Edited by TCAdmin on 05-12-2008 12:21 PM
Raghu_devRaghu_dev
Thanks Chris.

Unfortunately it didnt work for me. But I found the reason why it didnt work. As I said earlier, the button on the page is a s-control and the code behind the s-control doesnt trigger unless the button is clicked.
And what I am trying to do is disabling the button on page render.

So, I decided to do a hidden s-control on page (just made height and width as zero) and did put the following code which controls the enable/disable functionality of the button. Please let me know if my explanation didnt really make sense.

And btw, completely off topic question, how did you put your code in a box on your earlier post.

function setupPage() {
sourceId = '{!Billing_Profile__c.Id}';
var status = '{!Billing_Profile__c.Status__c}';
//var reqChng = document.getElementById('00b70000000zDze');
var reqChng = parent.document.getElementsByName('request_change');
alert ("Status from Controller - " + status);
//source.output.innerHTML = status;
if (status == "Pending")
{
reqChng[0].disabled = "true";
}
}

Message Edited by Raghu_dev on 05-13-2008 06:49 AM
Greg HGreg H
I recently wrote a post on this topic a while back.  I would re-post in this discussion but it is quite lengthy.  I think my solution is exactly what you are looking to do but I'll let you be the judge http://www.interactiveties.com/b_button_display.php.
-greg