Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global static void getIncident(String subject){
- Http http = new Http();
- HttpRequest req = new HttpRequest();
- HttpResponse res = new HttpResponse();
- string text = subject;
- 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');
- req.setMethod('GET');
- req.setHeader('Content-Type', 'application/json');
- String username = 'admin';
- String password = 'xxxxxx';
- Blob headerValue = Blob.valueOf(username + ':' + password);
- String authorizationHeader = 'BASIC ' +
- EncodingUtil.base64Encode(headerValue);
- req.setHeader('Authorization', authorizationHeader);
- res = http.send(req);
- System.debug('jsonrResult :' + res.getBody());
- Deserialization.ResponseResult result = (Deserialization.ResponseResult)JSON.deserialize(res.getBody(), Deserialization.ResponseResult.class);
- System.debug('Results == :' + result );
- List<Case> casesToUpsert = new List<Case>();
- for(Deserialization d : theresult.result ){
- Case c = new Case();
- c.Priority = d.impact;
- c.Status = d.incident_state;
- c.Subject = d.short_description;
- c.ServiceNowId__c = d.sys_id;
- c.Origin = d.contact_type;
- casesToUpsert.add(c);
- }
- system.debug('Cases to UPsert ::: ' +casesToUpsert);
- if(casesToUpsert.size()>0){
- Database.upsert(casesToUpsert,false) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement