E-Bonding, Received Correlation ID

Naveen87
Tera Guru

Hello Developers,

 

We are doing E-bonding b/w X & Y companies.

X company is passing Incident data & it's flowing as expected & creating ticket on Y company Incident table with information passed.

 

I want to receive the ticket number created on Y company on correlation ID field of X company, to confirm that ticket is created.

 

I have done below stuff but not receiving it. Not sure what is missed.

Please guide me

 

Naveen87_0-1711014869994.png

 ebondIncidentUpdate: function() {
		//var pathParams = request.pathParams; 
		//var table = pathParams.tableName;
		var requestBody = request.body;
		var requestData = requestBody.data;
		
	

		if (requestData.u_partner_ticket_id == undefined || requestData.u_partner_ticket_id == '')
		{
			response.setError(new sn_ws_err.BadRequestError('Correlation ID is missing'));
			return;
		}
		if (requestData.number == undefined || requestData.number == '')
		{
			response.setError(new sn_ws_err.BadRequestError('Number is missing'));
			return;
		}

		var gr = new GlideRecord('incident');
		gr.addQuery('number', requestData.number);
		gr.query();
		if (gr.next()) {
			gr.correlation_id = requestData.u_partner_ticket_id;
			gr.update();
		} else {
			response.setError(new sn_ws_err.BadRequestError('Incident not found'));
			return;
		}
		//  start building response object
		response.setStatus(200);
		response.setContentType('application/json');

		var body = {
			status: 'ok',
			requesterId: gr.number,
			providerId: gr.correlation_id,
			sys_id: gr.getUniqueValue()
		};

		response.setBody(body);
			var jsonObj = JSON.parse(responseBody)
        var ticketid = jsonObj.result.u_partner_ticket_id;
	},

 

1 ACCEPTED SOLUTION

Naveen87
Tera Guru

Please ignore.

I have found the solution.

I had to modify the BR.

var response = r.execute();
        var responseBody = response.getBody();
        gs.info("responseBody Wipro" + responseBody);
		var jsonObj = JSON.parse(responseBody)
        var ticketid = jsonObj.result.u_partner_ticket_id;
        current.correlation_id = ticketid;
        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;
    }

View solution in original post

9 REPLIES 9

Naveen87
Tera Guru

Please ignore.

I have found the solution.

I had to modify the BR.

var response = r.execute();
        var responseBody = response.getBody();
        gs.info("responseBody Wipro" + responseBody);
		var jsonObj = JSON.parse(responseBody)
        var ticketid = jsonObj.result.u_partner_ticket_id;
        current.correlation_id = ticketid;
        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;
    }

Bingo @Naveen87 !

 

Yes, exactly. Here you've parsed the response body and updated from it. 

 

Can you mark my answer helpful and correct.

 

Regards,

Amit 

@Amit Pandey ,

Sure. Guide me on this & I will mark it.

 

I want to check, If correlation ID is already set or empty.

If correlation id contains 'euwbond'. Then we are fine.

If it's something else then we want to show an error msg.

 

Please guide me with line of code to written on BR.

Naveen87_0-1711025799670.png

 

I used this but something is wrong.

no correlation id was created.

   if (correlationId.indexOf("euwbond:") !== -1) {
                if (correlationId === "euwbond:") {
                    // Correlation ID is fine
                    gs.addInfoMessage("Correlation ID is already set.");
                } else {
                    // A new ID came in through another
                    gs.addErrorMessage("A new ID came in through another.");
                }
            } else {
                // Correlation ID does not contain EUW
                gs.addErrorMessage("Correlation ID does not contain EUW.");
            }
    

 

Whole BR.

(function executeRule(current, previous /*null when async*/ ) {


        try {
            var r = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');
            r.setStringParameterNoEscape('u_customer_ticket_id', current.number);
            r.setStringParameterNoEscape('u_shr_priority', current.priority);
            r.setStringParameterNoEscape('u_shr_assignment_group', current.getDisplayValue('assignment_group'));
          
            var response = r.execute();
            var responseBody = response.getBody();
            gs.info("responseBody Wipro" + responseBody);


            // if (correlationId.indexOf("euwbond:") !== -1) {
            //     if (correlationId === "euwbond:") {
            //         // Correlation ID is fine
            //         gs.addInfoMessage("Correlation ID is already set.");
            //     } else {
            //         // A new ID came in through another
            //         gs.addErrorMessage("A new ID came in through another.");
            //     }
            // } else {
            //     // Correlation ID does not contain EUW
            //     gs.addErrorMessage("Correlation ID does not contain EUW.");
            // }
    


    var jsonObj = JSON.parse(responseBody)
    var ticketid = jsonObj.result.u_partner_ticket_id; current.correlation_id = 'euwbond:' + ticketid;
    var httpStatus = response.getStatusCode();
}
catch (ex) {
    var message = ex.message;
}

})(current, previous);

Hi @Naveen87 ,

 

Your code looks mostly correct, but there are a couple of adjustments needed. 

 

(function executeRule(current, previous /*null when async*/ ) {
    try {
        var r = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');
        r.setStringParameterNoEscape('u_customer_ticket_id', current.number);
        r.setStringParameterNoEscape('u_shr_priority', current.priority);
        r.setStringParameterNoEscape('u_shr_assignment_group', current.getDisplayValue('assignment_group'));

        var response = r.execute();
        var responseBody = response.getBody();
        gs.info("responseBody Wipro" + responseBody);

        var jsonObj = JSON.parse(responseBody);
        var ticketid = jsonObj.result.u_partner_ticket_id;
        current.correlation_id = 'euwbond:' + ticketid;

        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;
    }
})(current, previous);