销售人员 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8085709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Salesforce JavaScript
提问by Havoc783
I'm constructing a button that a user can click once they've opened a case to take ownership and set the status to active. Although I had the code pretty close, but I'm getting an error I'm not familiar with.
我正在构建一个按钮,用户可以在打开案例以获取所有权并将状态设置为活动后单击该按钮。虽然我的代码非常接近,但我收到了一个我不熟悉的错误。
Here's my code:
这是我的代码:
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
var url = parent.location.href;
var record = {!GETRECORDIDS($ObjectType.Case)}; //Looking for current case ID
var updateRecord;
var update_Case = new sforce.SObject("Case");
update_Case.Id = record;
update_Case.User = {!$User.Id};
update_Case.Status = "Active";
updateRecord.push(update_Case);
result = sforce.connection.update(updateRecord);
parent.location.href = url;
I'm getting this error:
我收到此错误:
A problem with the OnClick JavaScript for this button or link was encountered:
identifier starts immediately after numeric literal
回答by Matt K
I couldn't get the code you posted to work, but this did:
我无法让您发布的代码起作用,但是这样做了:
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var updateRecord = new Array();
var myquery = "SELECT Id FROM Case WHERE Id = '{!Case.Id}' limit 1";
result = sforce.connection.query(myquery);
records = result.getArray("records");
if(records[0])
{
var update_Case = records[0];
update_Case.OwnerId = "{!$User.Id}";
update_Case.Status = "Active";
updateRecord.push(update_Case);
}
result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;
Looking at it more, I think the code you posted is erroring because of the update_Case.User = {!$User.Id};
statement. There is no User field on Case, and the User.Id global variable should be placed in quotes (for JavaScript), like this: update_Case.OwnerId = "{!$User.Id}";
看多了,我觉得你贴的代码是因为update_Case.User = {!$User.Id};
语句出错了。Case 上没有 User 字段,User.Id 全局变量应该放在引号中(对于 JavaScript),如下所示:update_Case.OwnerId = "{!$User.Id}";
回答by Vinod Reddy
This might save you a query, may be.
这可能会为您节省一个查询,可能是。
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var url = parent.location.href;
var update_Case = new sforce.SObject("Case");
update_Case.Id = '{!Case.Id}';
update_Case.OwnerId = '{!$User.Id}';
update_Case.Status = 'Active';
result = sforce.connection.update(update_Case);
parent.location.href = url;
回答by Praveenkumar
`{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var newRecords = [];
var c = new sforce.SObject("Case");
c.id ="{!Case.Id}";
c.User = {!$User.Id};
c.Status = "Active";
newRecords.push(c);
result = sforce.connection.update(newRecords);
window.location.reload();`