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
sushanth s 2sushanth s 2 

Incident field is not created in serviceNow

Hi,

   I'm trying to create incident in serviveNow from saesforce case for that i developed apex class and trigger but it won't shown ant errors so anyone check the code and findout where should i made mistake .after the case created i'm checked ij serviceNow but incident not created .


This is my apex class and trigger

apex class :

global class ServiceNow{      
   @future       
    public static void servicenowPost(Id CaseId){ 
    Case c = [Select Id, CaseNumber,Status from Case where Id =: CaseId limit 1];         
    Http http = new Http();         
    HttpRequest req =  new HttpRequest();         
    HttpResponse res = new HttpResponse();                  
    String username = 'admin';         
    String password = '$Test12345';                  
    Blob headerValue = Blob.valueOf(username + ':' + password);         
    String authorizationHeader = 'BASIC ' +         EncodingUtil.base64Encode(headerValue);               req.setHeader('Authorization', authorizationHeader);                  
req.setEndpoint('https://dev23577.service-now.com/');         
req.setMethod('POST');        
 req.setHeader('Content-Type', 'application/json');                  
JSONGenerator gen = JSON.createGenerator(true);        
 gen.writeStartObject();                 
 //you can add as many mappings as you want        
 gen.writeStringField('Number', c.CaseNumber);        
 gen.writeStringField('State', c.Status);                 
 gen.writeEndObject();                 
 //you can now use String pretty as your body         
String pretty = gen.getAsString();                 
 req.setBody(pretty);         
res = http.send(req);                  
system.debug(res.getBody());     
      }
}


trigger :

trigger servicenow on Case (after insert){
                                                 
  ServiceNow.servicenowPost(trigger.new[0].Id);                                                                          
 
 }

Thanks
 
Prithviraj_ChavanPrithviraj_Chavan
Hi sushanth s 2,
Can you check status of you response by res.getStatus() and res.getStatusCode()