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
KenSKenS 

Convert button to inline SControl - please help

Hi,
I'm guessing this will take someone 2 mins for someone but I've been struggling for quite a bit longer.
I'm almost there with my first Scontrol (thanks to the excellent resources on these boards)

I've got the functionality I'm after working with a button but now I want to take it to the next step and make at inline scontrol that executes when someone looks at the page.

Can someone please hep and advise the tweaks required. (and if there are any other obvious changes that should be made etc .. feel free comment)


Ken

Code:
 <script
src="/soap/ajax/10.0/connection.js"
type="text/javascript"></script>

<script>


queryResult = sforce.connection.query(
"SELECT Stock__r.GSTcostallocation__c FROM Opportunity_to_Stock__c where Opportunity__r.Id = '{!Opportunity.Id}'")
queryResultIterator = new sforce.QueryResultIterator(queryResult)
total = 0
while(queryResultIterator.hasNext())
{ Stock_Sub = queryResultIterator.next()
total += Stock_Sub.Stock__r.getFloat('GSTcostallocation__c')
}
oppty = new sforce.SObject("Opportunity")
oppty.Id = "{!Opportunity.Id}"
oppty.GSTcostallocation__c = total
result = sforce.connection.update([oppty])


</script>

 

sfdcfoxsfdcfox
Looks good to me. Almost any button can be converted to an inline s-control with no modifications, so it appears to me that this would work fine. Do you get any errors or does it not run? I can't see an immediately obvious reason why it shouldn't...