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
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
Share
Improve this question
edited Oct 31, 2014 at 12:05
Yogesh D
1,6812 gold badges23 silver badges39 bronze badges
asked Nov 10, 2011 at 20:16
Havoc783Havoc783
1574 gold badges6 silver badges19 bronze badges
2
- the ment code is it // instead of \\ ? – Nettogrof Commented Nov 10, 2011 at 20:22
- Yea, sorry about that. I added the ment in the post. – Havoc783 Commented Nov 10, 2011 at 20:24
3 Answers
Reset to default 5I 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}";
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;
`{!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();`