Integration between servicenow and Powerautomate

Devi
Tera Contributor

I have a requirement to initiate teams bridge call automatically for P1 and P2 incident.

For P2 incident I have created one ui action as "Initiate teams meeting" so that when we click on that button it should call rest api of power automate and need to send the bridge details to those attendees.

Attendees i am populating from sys_user table. below is the code however if I am passing the attendee value statically we are receiving emails bit if we are passing the value dynamically we are not receiving the email but getting http status code as 202.

Code in UI Action:

{
    current.u_teams_meeting = "Yes";
    current.update();
    
    var number = String(current.number);
    var priority = current.priority;
    var location = current.getDisplayValue('u_site_id');
    var businessservice = current.getDisplayValue('business_service');
    var string = "P2" + " - " + number + " - " + location + " - " + businessservice;
    var startdate = current.sys_updated_on;
    var string9 = startdate.getDisplayValue();
    gs.log("startdate" + string9);
    var date1 = new GlideDateTime(startdate);
    var hours = 60 * 60;
    date1.addSeconds(hours);
    var endtime = date1.getDisplayValue();
    gs.log("endtime in initiate meting" + endtime);
    var shortdescription = current.short_description.replace(/(\r\n|\n|\r|['"])/gm, ", ");
    gs.log("shortdescription" + shortdescription);

// here we are getting the same value "graham@email.ca; jane@email.ca" as attendees1 variable

    var attendees = current.getDisplayValue('u_attendee_email'); /
    var attendees2 = String(attendees);
    gs.log("attendees2" + attendees2);
    var attendees1 = "graham@email.ca; jane@email.ca";
    var request = new sn_ws.RESTMessageV2();
    var requestBody = {
        "IncidentNumber": string,
        "Start": string9,
        "End": endtime,
        "Message": shortdescription,
        "Attendees": attendees2
    };

    gs.log("RequestBody" + requestBody);
    request.setRequestBody(JSON.stringify(requestBody));
    request.setEndpoint('REST API OF POSTMAN URL');

    gs.log("RequestBody in json" + request.setRequestBody(JSON.stringify(requestBody)));

    request.setHttpMethod('POST');
    request.setRequestHeader("Accept", "application/json");
    request.setRequestHeader('Content-Type', 'application/json');

    var response = request.execute();

    var responseBody = request.getBody();

    gs.log("responseBody" + responseBody);

    var httpStatus = response.getStatusCode();
    gs.log("Statuscode" + httpStatus);
    var parsedData = JSON.parse(responseBody);
    gs.log("Parseddate" + parsedData);

    gs.log("Response in BR" + response.getBody());

}

2 REPLIES 2

Devi
Tera Contributor

Issue Resolved

Lolo Villalba
Tera Contributor

How?