You need to sign in to do that
Don't have an account?
TotalNovice
Custom button to update calc field
My goal is to calculate seats left for a class by subtracting number of registered enrolees from facility capacity.
Can I use following code in S-Control (Javascript snippet) to attach it to a custom button which will update Seats Left field on the class page?
<SCRIPT language="javascript">
SforceCommand cmd = new SforceCommand("select Count(distinct Contact__c) from SFDC_Enrollment__c where Class__c =" + {!SFDC_Class__c.Id}+ " AND Status__c = 'Registered'");
int ret = cmd.ExecuteQuery();
cmd.Text = "update SFDC_Class__c Set Seats_Available__c = Max_Capacity__c - " + ret + " where Class__c = " + {!SFDC_Class__c.Id};
cmd.ExecuteNonQuery();
</SCRIPT>
SOQL only supports query. The ajax toolkit can what you want, but you'll have to adhere to the semantics of the Apex API and not, unfortunately, the ADO api.
Cheers