OnClick Java Script Button -如果字段等于x,则更新其他字段为a,否则更新其他字段为B

OnClick Java Script Button - If field equals x then update other field to a, else update other field to B

本文关键字:字段 更新 其他 Button Script Java 如果 OnClick      更新时间:2023-09-26

我在一个自定义对象和新的JavaScript工作。我想创建一个按钮如果一个字段等于x,那么更新另一个字段为a,如果这个字段等于y,那么更新另一个字段为B,如果字段为空,那么发送警报。

我得到了按钮工作来更新我需要的字段,但是当我试图创建if/then时,我得到了语法错误。

到目前为止我写的是:

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")} 
var objPrice_Quote__c = new sforce.SObject('Price_Quote__c'); 
objPrice_Quote__c.Id = '{!Price_Quote__c.Id}'; 
objPrice_Quote__c.Status__c = 'Customer Approval'; 
var result = sforce.connection.update([objPrice_Quote__c]); 
location.reload(true);

我甚至没有在代码中看到if语句....试试这个。

var theFieldToSet = document.getElementById("field1");
var button = document.getElementById("button");
button.onclick = function () {
    if (theFieldToSet.innerHTML == "x") {
        theFieldToSet.innerHTML = "A";
    }
};