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.
- First create a rest S3 connection using
- rest api base url like https://hostname,
- security as aws Signature version 4 and
- access key, secret key, aws region like US West(Oregon) Region (us-west-2) and service name Amazon S3.
- 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.
- Zip the file. Provide logFileZipName and directory to zip and output directory.
- Configure the S3 rest connection and provide
- relative url as /{pathAndFileName},
- verb put ,
- provide request payload as Binary and media type of the request body as application/zip.
- In the map, assign pathandFilename to template param and zip reference to stream reference.
- Update that log created = Y
To create Incident:
- 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.
- Use that connection and configure in the integration and
- provide relative uri "/api/now/table/incident" in this case,
- verb as post
- Provide request and response JSON sample payload
- then map the request payload.
No comments:
Post a Comment