Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. global class JIRATaskWebserviceCalloutSyncFields {
  2. @future (callout=true)
  3. WebService static void syncfields(String JIRA_Key) {
  4. //Modify these variables:
  5. String username = 'venkatdavuluri';
  6. String password = 'Wildcraft@987';
  7. String jiraURL = ' http://jira.hdwuotecenter.com';
  8.  
  9. sObject s = [SELECT Subject, Assignee__c, Priority, Requested_By__c FROM Task WHERE JIRA_Key__c = :JIRA_key LIMIT 1];
  10. String c_summary = (String) s.get('Subject');
  11. String c_assignee = (String) s.get('Assignee__c');
  12. String c_priority = (String) s.get('Priority');
  13. String c_requested_by = (String) s.get('Requested_By__c');
  14.  
  15. String priorityId;
  16. //Map Salesforce Prority to JIRA Prority
  17. if (c_priority == 'Blocker') { // Salesforce.com Priority
  18. priorityId = '1'; // JIRA Priority ID
  19. } else if (c_priority == 'Critical') {
  20. priorityId = '2';
  21. } else if (c_priority == 'Major') {
  22. priorityId = '3';
  23. } else if (c_priority == 'Minor') {
  24. priorityId = '4';
  25. } else if (c_priority == 'Trivial') {
  26. priorityId = '5';
  27. }
  28.  
  29. //Construct HTTP request and response
  30. HttpRequest req = new HttpRequest();
  31. HttpResponse res = new HttpResponse();
  32. Http http = new Http();
  33.  
  34. //Construct Authorization and Content header
  35. Blob headerValue = Blob.valueOf(username+':'+password);
  36. String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
  37. req.setHeader('Authorization', authorizationHeader);
  38. req.setHeader('Content-Type','application/json');
  39.  
  40.  
  41. //Construct Endpoint
  42. String endpoint = jiraURL+'/rest/api/2/issue/'+JIRA_Key;
  43.  
  44. //Set Method and Endpoint and Body
  45. req.setMethod('PUT');
  46. req.setEndpoint(endpoint);
  47. req.setBody('{ "fields":{"summary": "'+c_summary+'", "assigne":{"name":"'+c_assignee+'"}, "priority":{"id":"'+priorityId+'"}, "customfield_10400":{"value":"'+c_requested_by+'"}}}');
  48.  
  49. try {
  50. //Send endpoint to JIRA
  51. res = http.send(req);
  52. } catch(System.CalloutException e) {
  53. System.debug('ERROR:' + e);
  54. System.debug(res.toString());
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement