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
sumpritsumprit 

Update a checkbox on click of a button

Hi there,

I would like "Ready to Convert" checkbox to be checked when a user clicks on CONVERT on Leads. Here is my code:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/12.0/connection.js"></script>


</script>
</head>

<script type="text/javascript">

function btnConvert_Click() {
// First we will make a reference to the CheckBox which is on the LEAD object.
// this is the second choice var chkReady = parent.document.getElementById("chkReady");

var chkReady = parent.document.getElementsByName("Ready_To_Convert__c");

// check if chkReady exists when this function is called.
if (chkReady != null) {
chkReady.checked = true; // check the checkbox.
}
}


<body onLoad="btnConvert_Click();"></body>
</html>

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

It gives me this error:-

btnConvert_Click is not defined

jpizzalajpizzala
One thing I see is that the script tag is not closed. Try adding </script> before the body tag to see if that will help.

Another thing, why are you setting the Ready To Convert checkbox when the record is being converted? If you want to see (for reporting purposes) if a Lead has been converted or not, there is an isConverted flag on the Lead natively. I don't know if this will help you, but it may be an easier way around the issue, depending on your business' goal.


Message Edited by jpizzala on 04-14-2008 05:05 PM
sumpritsumprit

Here is the edited version of the code:-

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/12.0/connection.js"></script>


</script>
</head>

<script type="text/javascript">

function btnConvert_Click() {
// First we will make a reference to the CheckBox which is on the LEAD object.
// this is the second choice var chkReady = parent.document.getElementById("chkReady");

var chkReady = parent.document.getElementsByName("Ready_To_Convert__c");

// check if chkReady exists when this function is called.
if (chkReady != null) {
chkReady.checked = true; // check the checkbox.
}
}

</script>
<body onLoad="btnConvert_Click();"></body>
</html>

 It still does not place CHECKMARK on the Ready to Convert box. Why ?

jpizzalajpizzala
A more solid approach would probably be to use the AJAX Toolkit's API access to change the field value. Accessing the generated field through the DOM won't be as reliable or flexible.

You may be able to accomplish the same thing using workflow or Apex. Is there a specific reason you are attempting this through an scontrol?
sumpritsumprit
I do not think it is possible through the workflow rule? How will I say, when the button is clicked ? Unless I write a formula? Is that what you suggesting?
jpizzalajpizzala
The button you are pressing is the Convert button, correct? So, theoretically, this will update the Lead record (at the very least the isConverted field will change to true). I haven't tried this out personally, but you should be able to create a workflow rule on the Lead object that executes whenever a Lead record is updated, check for the isConverted flag as proof that the Lead was actually converted, then select your custom field checkbox.


Message Edited by jpizzala on 04-16-2008 05:29 PM
SunilSunil

Hi, 

Try with these lines: -

Code:
var xyz= new sforce.SObject("ABC__c"); 
xyz.set("Id", "{!ABC__c.Id}"); 
xyz.set("Generated_A_R_Merge_Document__c",true); 
var saveResult = sforce.connection.update([xyz]); 

where 'ABC__c' is the name of the object.

'Generated_A_R_Merge_Document__c' is the name of checkbox field.
 
Sunil



Message Edited by Sunil on 04-18-2008 01:03 AM
sumpritsumprit
Thanks for the reply.

This is now fixed.


gemziebethapgemziebethap

Sunil - what is this - Apex or ...?