You need to sign in to do that
Don't have an account?
How to store who clicked a custom button in a custom field
We have a custom button that executes JavaScript on our case record:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
this.disabled=true;
try{
var accId='{!Account.Id}';
var objectId = '{!Case.Id}';
var result = sforce.apex.execute("ForceJiraComm", "createIssue",
{case_id : objectId});
alert(result);
location = location;
}
catch(err) {
txt="There was an error on this page.\n\n";
txt+="Error description: " + err + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
this.removeAttribute('disabled');
We want it to also write the full name of the user that clicked the button to the custom field JIRA_Escalated_By__c on the case object. How do we do this?
Basically, how can update our APEX to store who clicks a custom button?”
<custom_object_name>.JIRA_Escalated_By__c = UserInfo.getUserId();
Replace the <custom_object_name> by your object name containing the field JIRA_Escalated_By__c. I am assuming you have already set up and instantiated the object in the function.
Hi,
inside the createIssue method of ForceJiraComm class, u can add the following code.
Case caseOBj = [Select Id, JIRA_Escalated_By__c FROM Case WHERE Id =: case_id];
// Incase if JIRA_Escalated_By__c is a look-up to User object
caseObj.JIRA_Escalated_By__c = Userinfo.getUserd();
// Incase if JIRA_Escalated_By__c is a String that just stores the User's Full Name
caseObj.JIRA_Escalated_By__c = [Select Name FROM User WHERE Id=: Userinfo.getUserd()].Name;
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Regards,
Arun.
No luck with this first solution. The second looks promising, but it's not working either. Still tinkering with the next.
This is what I'm using:
Case caseOBj = [Select Id, JIRA_Escalated_By__c FROM Case WHERE Id =: case_id];
caseObj.JIRA_Escalated_By__c = [Select Name FROM User WHERE Id=: Userinfo.getUserId()].Name;
It's not throwing errors, but it's not putting my name in teh "JIRA Escalated By" field when I click the button.
Here is where i have this in my code:
WebService static String createIssue(String case_id) {
List<String> caseIds = new List<String>();
caseIds.add(case_id);
List<Case> cases = ForceJiraComm.getCasesByID(caseIds);
Case escalated_case = cases[0];
Case caseOBj = [Select Id, JIRA_Escalated_By__c FROM Case WHERE Id =: case_id];
caseObj.JIRA_Escalated_By__c = [Select Name FROM User WHERE Id=: Userinfo.getUserId()].Name;
String escalation_type = escalated_case.JIRA_Escalation_Type__c;
if(escalation_type==null)
return 'You must provide a JIRA Escalation Type to send this to JIRA.';
if((escalated_case.Escalated_to_RND__c != null) &&
(escalated_case.JIRA_Resolution_Date__c == null))
return 'You cannot send a new escalation to JIRA until the current escalation is resolved.';
//Construct Endpoint
String endpoint = ForceJiraComm.BASE_URL + '/rest/customware/connector/1.0/' +
ForceJiraComm.SYSTEM_ID + '/Case/'+ case_id + '/issue/create.json';
Note there are 90 lines before and 700 after this excerpt.
Thanks...
Hi,
PSB, hope this will helps u.
http://salesforce.stackexchange.com/questions/2231/how-can-i-update-a-field-with-a-custom-button
http://boards.developerforce.com/t5/General-Development/Update-a-field-value-with-a-new-custom-button/td-p/67282
Regards,
Rajesh.
Hi,
Try this,
which will update with current user.
{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
var Account = new sforce.SObject("Account");
Account.id = "{!Account.Id}";
Account.hello__c= "{!$User.Id}";
var result = sforce.connection.update([Account]);
if (result[0].getBoolean("success"))
{
// Refresh window
window.location.reload();
}
else
{
alert("Error saving lead");
}
Regards,
Rajesh.