1

Hello Stackexchange community.

I'm trying to create a button that will allow to make some calculations based on the field in Custom Object (Contract_Information__c in my case). I've written this code, but the result is the alert message with "Unexpected Identifier".

    !requireScript("/soap/ajax/26.0/connection.js")} 

    var ContractInfoObj = new sforce.SObject("Contract_Information__c"); 
    var account = new sforce.SObject("Account"); 

    ContractInfoObj.id = "{!Contract_Information__c.Id}"; 
    account.id = "{!Account.Id}"; 

    if ("{!Account.Account_Status__c}" == "Yes") 
    { 

    if ("{!Contract_Information__c.Contract_Type__c}" == "Opt1"){ 
    ContractInfoObj.Field1__c = ContractInfoObj.Field2__c * 0.1};}

    if ("{!Contract_Information__c.Contract_Type__c}" == "Opt2"){ 
    ContractInfoObj.Field1__c = ContractInfoObj.Field2__c * 0.2};}

    var result = sforce.connection.update([ContractInfoObj]); 
    }
    else
    { 
    alert("Please update Account Status to "Yes"); 
    }

Am i using the right approach to identify the custom object in this code?

I'd really appreciate any advices/comments provided!

Thanks in advance,

0

1 Answer 1

0

In my mind, you have one bracket in excess, on the two lines "ContractInfoObj.Field2__c * 0.1" and "ContractInfoObj.Field2__c * 0.2" because you open one bracket and close two. So just delete the bracket after them (keep the ";}"

Otherwise, if you are on the Contract_Information page, i'm not sure that the "{!Account.Account_Status__c}" and the others fields have a value. Do you have made a test with a alert() in order to see the value ? I think you must query the Account record, whith your Contract_Information__c.Account__c field as the id.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .