Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. global static void getIncident(String subject){
  2.  
  3. Http http = new Http();
  4. HttpRequest req = new HttpRequest();
  5. HttpResponse res = new HttpResponse();
  6.  
  7. string text = subject;
  8.  
  9. req.setEndpoint('https://dev24994.service-now.com/api/now/table/incident?sysparm_fields=impact%2Cincident_state%2Csys_updated_onONLast%2520minute%40javascript%3Ags.minutesAgoStart(30)%40javascript%3Ags.minutesAgoEnd(0)%2Cshort_description%2Csys_id%2Ccontact_type&u_sftype=true&sysparm_limit=10');
  10. req.setMethod('GET');
  11. req.setHeader('Content-Type', 'application/json');
  12.  
  13. String username = 'admin';
  14. String password = 'xxxxxx';
  15.  
  16. Blob headerValue = Blob.valueOf(username + ':' + password);
  17. String authorizationHeader = 'BASIC ' +
  18. EncodingUtil.base64Encode(headerValue);
  19. req.setHeader('Authorization', authorizationHeader);
  20.  
  21. res = http.send(req);
  22. System.debug('jsonrResult :' + res.getBody());
  23.  
  24. Deserialization.ResponseResult result = (Deserialization.ResponseResult)JSON.deserialize(res.getBody(), Deserialization.ResponseResult.class);
  25. System.debug('Results == :' + result );
  26.  
  27. List<Case> casesToUpsert = new List<Case>();
  28. for(Deserialization d : theresult.result ){
  29.  
  30. Case c = new Case();
  31. c.Priority = d.impact;
  32. c.Status = d.incident_state;
  33. c.Subject = d.short_description;
  34. c.ServiceNowId__c = d.sys_id;
  35. c.Origin = d.contact_type;
  36.  
  37. casesToUpsert.add(c);
  38.  
  39. }
  40. system.debug('Cases to UPsert ::: ' +casesToUpsert);
  41.  
  42. if(casesToUpsert.size()>0){
  43. Database.upsert(casesToUpsert,false) ;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement