You need to sign in to do that
Don't have an account?
MnZ321
Attempting to post Case parameters to external system
I'm a beginner in webservices and future calls. I have been trying post parameters to an external system (ServiceNow). As of now I'm able to post a generic description field from Salesforce to ServiceNow.
Here's what I have tried so far, trigger....
Currently I'm able to create a record in external system, but not able to post the parameters included (short_description in this case). Am I missing something? Thanks in advance.
I would really appreciate if I'm pointed to the right direction. Thanks in advance.
Here's what I have tried so far, trigger....
trigger Case2ServiceNow on Case (after insert) { AuthCalloutPost.basicAuthCalloutPost(Trigger.newmap.keyset()); }Apex...
public class AuthCalloutPost1{ public String Response { get; set;} @future(callout=true) public static void basicAuthCalloutPost(Set<Id> caseids){ //call to generate request body String requestbody = generateBody(caseids); System.debug('##requestbody##'+requestbody); HttpRequest req = new HttpRequest(); req.setEndpoint('xxx/now/table/incident'); req.setMethod('POST'); req.setBody(requestbody); req.setTimeout(120000); String authorizationHeader = 'Basic xxx='; req.setHeader('Authorization', authorizationHeader); req.setHeader('Accept', 'application/json'); req.setHeader('Content-Type', 'application/json'); Http http = new Http(); HTTPResponse res = http.send(req); System.debug('##res##'+res); System.debug('##res.getBody##'+res.getBody()); // this.response=res.getBody(); } //This method will generate request body. public static String generateBody(set<id> casesids) { JSONGenerator gen = JSON.createGenerator(true); gen.writeStartObject(); gen.writeFieldName('My_Cases'); gen.writeStartArray(); for(Case c : [Select Id, RecordTypeId, RecordType.Name, Subject From Case Where Id IN : casesids]) { if(c.RecordType.Name == 'Incident'){ //define different fields which you want to pass. gen.writeStartObject(); gen.writeStringField('short_description',c.Subject); gen.writeEndObject(); } else{ System.debug('not incident'); } } gen.writeEndArray(); gen.writeEndObject(); return gen.getAsString(); } }I'm trying to post Salesforce Case parameters to the ServiceNow like name, description, because a description is enough to create an incident.
Currently I'm able to create a record in external system, but not able to post the parameters included (short_description in this case). Am I missing something? Thanks in advance.
I would really appreciate if I'm pointed to the right direction. Thanks in advance.
modify your code like this...
DEBUG|##requestbody##{
"Cases" : [ {
"short_description" : "Parameter yo"
} ]
}