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
saarikosaariko 

Update a check box in a custom object using an S-control

subject says it all
I have a custom object, it has about 25 checkboxes. I want to update the selected checkboxes accorinding to pressing on a link.
How can I do it?
 
a more specific detail:
cb's 1,2,3,4,5 need to be selected if custom link 1 is pressed.
cb's4,5,6,7 need to be selected if custom link 2 is pressed (uncheck the rest)
 
Anyone?
gsickalgsickal
Here is some code to set a single checkbox to true. You could also set it to false and add more fields here. This code would be executed when custom link 1 was pressed. You could do a similar thing when the other was pressed.

try {
var updateObjects = new Array();
var obj = new Sforce.Dynabean("YourObjectName__c");

obj.set("Id", "{!YourObjectName_ID}");
obj.set("YourCheckboxFieldName__c", new Boolean(true));

updateObjects.push(obj);
var sr = sforceClient.Update(updateObjects)[0];
}
catch (ex) {
alert(ex);
}
saarikosaariko

Hi and thank you for your answer.

I did anter the text you have given me, but when pressing the link, all I got was that text in a window.

There must be some more I need to put in? how come I see the text and it's not doing what I want?

gsickalgsickal
What I sent was only a piece of the code you need, not all of it. I don't know how your custom link is calling your scontrol, but this code snippet would go inside your scontrol when custom link 1 is pressed. You'll have to add the lines of code to set the other checkbox values that you want, and do something similar when custom link 2 is pressed.


If the fields you are trying to update are checkboxes, the line of code that does this is either


obj.set(cb1name, new Boolean(true)); or
obj.set(cb1name, new Boolean(false));


where "cb1name" is the actual name of your checkbox field.


Make sure you replace "Your..." fieldnames ini the 3 lines below to match your actual object names. If this still doesn't work, post a code snippet so we can take a look...


var obj = new Sforce.Dynabean("YourObjectName__c");
obj.set("Id", "{!YourObjectName_ID}");
obj.set("YourCheckboxFieldName__c", new Boolean(true));

Message Edited by gsickal on 06-11-2006 09:27 AM

saarikosaariko

 

Message Edited by saariko on 06-12-2006 04:13 AM

saarikosaariko

 

Message Edited by saariko on 06-12-2006 04:13 AM

saarikosaariko

EUREKA !!  :-)

Ok, phase 1 is complete. I am able to update the cb in a page, and reload it. Next request will be:

I want to have a custom link to clear (set to false) all of the cb's in the object (I have a bout 70). I am trying some for loop, but DOH.  please see attached code, and if ne1 can advise, please:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<script
 src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js"
 type="text/javascript"></script>
<script type="text/javascript">
 function initPage()
 {
//  alert(window.parent.parent.parent.location.href);
     sforceClient.registerInitCallback(setupPage);
     sforceClient.init("{!API_Session_ID}"," {!API_Partner_Server_URL_70}");
 }
    function setupPage( )
    {
    // alert("{!Boreg_ID}");
     try {
   var updateObjects = new Array();
   var obj = new Sforce.Dynabean("Boreg__c");
  
   obj.set("Id", "{!Boreg_ID}");
   // This line will clear all settings
   for (var k in obj.records) { obj.records[k].set(new Boolean,false); }
   
//   for ( var x = 1 ; x < obj.get( ; x++ )
//   {
//    obj.set("X1__c", new Boolean(true));
//    obj.set("X2__c", new Boolean(true));
//   }
   updateObjects.push(obj);
   var sr = sforceClient.Update(updateObjects)[0];
   
   refreshWindow();
  }
  catch (e) { alert(e); }
    }
    
    function refreshWindow(){
  //alert("inside refreshWindow()");
  //alert(window.parent.parent.parent.location.href);
  try{
   parent.parent.location.replace("/{!Boreg_ID}");
  } catch (e) { alert(e); }
 }
            
       </script>
</head>
</html>
<body onload=initPage();>
<center>
<br><br><br>
<SPAN STYLE=" font-size: 75%; font-family: 'Arial', 'Helvetica', sans-serif;">
Updating item... Please Wait.
</span><br><br>
<img src="/img/waiting_dots.gif" alt="Please wait..." title="Please wait..." height="20" width="196">
</center>
</body>

 

 

FinTechFinTech
Hi I've got a similar kind of requirement but I need to update the requesting page (i.e. the page that has your scontrol). Do you know if it is possible to update the checkbox to do this?