Monday, June 7, 2021

OIC - send Notification - email, log file and create incident

Usecase: Here, we will create a reusable component "Notification service" and we will perform following functions:

  • Send Email
  • Create Incident
  • LogFile
Rest Request Json:
"sendEmailFlag": "Y",
"emailFrom": "",
"emailSubject": "",
"emailBody": "",
"attachmentFlag": "",
"attachmentBase64Reference": "",
"createIncidentFlag" : "",
"incidentCallerId" : "",
"incidentBusinessService" : "",
"incidentCategory" : "",
"incidentSubcategory: "",
"incidentContactType": "",
"incidentShortDescription" : "",
"incidentDescription" : "",
"createLogFileFlag" : "",
"directoryAdaptet" : "",
"logDescription" : "",
"logFileName" : ""

Response rest Json:

"emailSent" : "",
"incidentCreated" : "",
"incidentId" : "",
"logCreated" : "",
"ExceptionCode" : "",
"ExceptionReason" : "",
"ExceptionDetails" : ""

To send email:

  • Create a app driven integration and take body scope
  • Within the body, take a switch block and check if sendEmailFlag = "Y" then 
  • Take a stage action and write a file for the attachment.
  • Take a notification action and provide all details like emailFrom, emailSubject, create a EMAIL_BODY param and assign with emailBody and use in the body section with {EMAIL_BODY}.
  • In the attachment section, add the write file reference. Or use decodebase64ToReference() to convert the feeded attachment base64 to reference.
  • Update the emailsent response as "Y"

To Log file:

Here i will log the zip file in the S3 bucket using rest call.
  1. First create a rest S3 connection using
    1. rest api base url like https://hostname, 
    2. security as aws Signature version 4 and
    3.  access key, secret key, aws region like US West(Oregon) Region (us-west-2) and service name Amazon S3.
  2. In the integration, check if createLogFlag = "Y" then , write the log file using stage action. Provide file name, output directory,provide a csv file etc and in the map, assign log description.
  3. Zip the file. Provide logFileZipName and directory to zip and output directory.
  4. Configure the S3 rest connection and provide 
    1. relative url as /{pathAndFileName}, 
    2. verb put ,  
    3. provide request payload as Binary and media type of the request body as application/zip.
    4. In the map, assign pathandFilename to template param and zip reference to stream reference.
    5. Update that log created = Y

To create Incident:

  1. As service now is a rest service so first create a rest incident service connection using base API base URI, basic authentication and provide user and password.
  2. Use that connection  and configure in the integration and
    1.  provide relative uri "/api/now/table/incident" in this case, 
    2. verb as post
    3. Provide request and response JSON sample payload
    4.  then map the request payload.

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...