2011-11-10 13 views
2

所有権を取得し、ステータスをアクティブに設定するために、ユーザーがケースを開いたら、ユーザーがクリックできるボタンを作成しています。私はかなり近いコードを持っていましたが、私は慣れていないエラーが発生しています。ここでSalesforce JavaScript

は私のコードです:

{!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; 

私はこのエラーを取得しています:

A problem with the OnClick JavaScript for this button or link was encountered: 
identifier starts immediately after numeric literal 
+0

コメントコードは//は\\の代わりにいるのですか? – Nettogrof

+0

そうです、ごめんなさい。投稿にコメントを追加しました。 – Havoc783

答えて

5

私はあなたが仕事に投稿されたが、これはやったコードを得ることができませんでした:

{!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; 

もっと見ると、投稿したコードはupdate_Case.User = {!$User.Id};声明。 CaseにUserフィールドはなく、User.Idグローバル変数は次のように引用符(JavaScriptの場合)に配置する必要があります。update_Case.OwnerId = "{!$User.Id}";

+0

Mattさん、ありがとうございました。それは私を台無しにしていた世界的な呼びでした。 – Havoc783

3

これにより、クエリが保存される可能性があります。

{!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; 
0
`{!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();` 
関連する問題