+ Start a Discussion

S-Control Update a Field?Please Help...any Help

Hi all:
   How do I update the answer I recvd from an S-Control to a field on the object????
Does anyone know how to do this? Pleaseee
I think you will have to provide a little more information for us to help you.

Sure No problem... Thank you for help thought

Below is my code ... Now from the answer from this s-control I want to update or place the answer into a field called Difference__c... I wanted to know how to do that..

<script type="text/javascript" language="javascript" src="/js/functions.js"></script> 
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script> 
<script type="text/javascript"> 
function two(x) {return ((x>9)—"":"0")+x}; 

function three(x) {return ((x>99)–"":"0")+((x>9)˜"":"0")+x}; 

function time() { 
var millennium =new Date("{!Delivery_Time__c.Actual_Arrival_Time__c}") ; 
var today=new Date("{!Dispatch_Schedule__c.Proposed_Arrival_Time__c}"); 
var cvt=millennium.getTime()-today.getTime(); 

var sec = Math.floor(cvt/1000); 
cvt = cvt % 1000; 
t = three(cvt); 

var min = Math.floor(sec/60); 
sec = sec % 60; 
t = two(sec) + ":" + t; 

var hr = Math.floor(min/60); 
min = min % 60; 
t = two(min) + ":" + t; 

var day = Math.floor(hr/60); 
hr = hr % 60; 
t = two(hr) + ":" + t; 
t = day + ":" + t; 

return t; 

var account = new sforce.SObject("Delivery_Time__c"); 

account.Id = result[0].id; 
account.Difference__c = time(); 

//var result = sforce.connection.update([account]); 


document.write("<font face='aria' color='red'>The Difference in Time is " + time()+"</font>"); 

<body bgcolor="#F3F3EC" onload="time()";> 


That helps. It looks like your issue is with this line:
account.Id = result[0].id; 

 You are referencing a Object that is not defined "result[0].id". In order for the save to work properly you will need to put in a valid Delivery_Time__c Id.  I would try replacing with this code:
account.Id = '{!Delivery_Time__c.Id}";

Also...your variable of "account" is misleading since you are actually trying to update the "Delivery_Time__c" object.
Let me know if this works.
Ok great.. Thanks for the help... I can not override the save button because I dont see that I can...
is there any other way of doing this? When they click new they see save, cancel... Unless you know the Action for clicking on Save?
Whoops. I am editing this post because my earlier statement was inccorect. Thanks TCAdmin  for replying and correcting my mistake!

Message Edited by tinman44 on 04-25-2008 09:48 AM

You are correct, you can't override the Save button. This is a common feature request within the system but isn't being planned as far as I know. The only way I have been able to 'do' this is by creating a custom edit page that I build from scratch. Within the Cookbook it gives you information on mimicking the Salesforce pages  and can assist with it. This is not easy to do though.
do you know what chapter is this on???
Well, rather than trying to override the Save button you should think about writing an Apex trigger if all you have to do is update some fields post-save.
Chapter 8