2

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
2
  • the comment code is it // instead of \\ ? Commented Nov 10, 2011 at 20:22
  • Yea, sorry about that. I added the comment in the post. Commented Nov 10, 2011 at 20:24

3 Answers 3

5

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}";

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Matt, that worked great. It was the global call that was messing me up.
3

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;

Comments

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();`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.