function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShaneJensenShaneJensen 

Add Current User to Case Team

Hi All,

I would like to add a Button to the Case layout that allows a user to add themselves to the Case Team with one click.  Is this possible?  Following on Chatter is not an option.  
 

Thanks,
Shane

Best Answer chosen by ShaneJensen
PeaceMakerPeaceMaker
Upsert is not possible as it requires an extetrnal ID field which is not possible in this situation.

but I tested the below code . It is not creating duplicates. so you can happily use this..

Try this  below code. remove the alert after testing ....

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

var rolename = "TTEST";
var qr = sforce.connection.query("SELECT Id,Name FROM CaseTeamRole where Name ='"+ rolename +"'");
var records = qr.getArray("records");
var rec = records[0];

var ct = new sforce.SObject("CaseTeamMember");
ct.MemberId = "{!$User.Id}";
ct.parentId="{!Case.Id}";
ct.TeamRoleID =rec.Id;
alert('Logged In User:'+ct.MemberId);
alert('Case ID:'+ct.parentId);
alert('TeamRoleID:'+ct.TeamRoleID);

var result = sforce.connection.create([ct]);
alert('Successfully Added to Case Team');
parent.window.location.reload();


Please dont forget to mark this as solution. if it works for you!

All Answers

Atul111Atul111
If this is possible.

For this you need to create a VF page, in this you can give the option to select user option.

And save this data in case team object. Please let me know if you have any query.

If this ans is solve you problem please accept this answer.
PeaceMakerPeaceMaker
Yes , you can achieve this by creating a custom button which fires on Execute Javascript Code to include the current user to Case Team. no need for a VF Page.
PeaceMakerPeaceMaker
Please find the below code which does this.....

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

var ct  = new sforce.SObject("CaseTeamMember");
ct.MemberId = "Loggedin User ID";
ct.parentId="Case Id";
var result = sforce.connection.insert([ct]);

if(result[0].getBoolean("success")){
window.location = "/" + '{!Case.Id}';
alert('Team Member Added to the Case!');
}


Pass the Case ID and Logged In User ID for MemberID and ParentId.  

Please mark this as Answer if it solves your problem.
ShaneJensenShaneJensen
That was pretty close, I had to use upsert, since CaseTeamMember doesn't support Insert.  Also, I had to set the TeamRoleID.  Here's the changes I made.

ct.TeamRoleID="Enter ID from CaseTeamRole";

var result = sforce.connection.upsert("Id",[ct]);
ShaneJensenShaneJensen
And thanks very much to both of you for the help.
PeaceMakerPeaceMaker
Upsert is not possible as it requires an extetrnal ID field which is not possible in this situation.

but I tested the below code . It is not creating duplicates. so you can happily use this..

Try this  below code. remove the alert after testing ....

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

var rolename = "TTEST";
var qr = sforce.connection.query("SELECT Id,Name FROM CaseTeamRole where Name ='"+ rolename +"'");
var records = qr.getArray("records");
var rec = records[0];

var ct = new sforce.SObject("CaseTeamMember");
ct.MemberId = "{!$User.Id}";
ct.parentId="{!Case.Id}";
ct.TeamRoleID =rec.Id;
alert('Logged In User:'+ct.MemberId);
alert('Case ID:'+ct.parentId);
alert('TeamRoleID:'+ct.TeamRoleID);

var result = sforce.connection.create([ct]);
alert('Successfully Added to Case Team');
parent.window.location.reload();


Please dont forget to mark this as solution. if it works for you!
This was selected as the best answer
ShaneJensenShaneJensen
Thanks again PeaceMaker.  This works great as is.