October 6, 2020

Send attachment in OIC notification


In this post I have explained how to send Attachments along with notification's body in OIC Notification action.

Knowledge :๐Ÿ‘€
The total size limit on a notification email is 1 MB for Oracle Integration and 2 MB for Oracle Integration Generation 2.


Steps overview to send attachment in OIC notification action  :

  • Open the Notification action and click on Plus  icon "+" to add attachments. 
  • Select the Attachments ( 'Reference' )to add.You can edit or delete the attachment once added. Click save and close.That's it. Your configuration for sending attachment in email notification completed.

 [You can take reference from below image:- Fig -1, Fig -2, Fig-3]



Info ๐Ÿ‘‰  File Reference are of different types.For example, in the below image the  integration includes three file reference attachments (highlighted in yellow) that are available for selection. You can select one or all as attachments.

  • An attachment from a REST Adapter connection
  • A file reference from a stage file write operation ⃕this case scenario I have covered in below hands-on practice.
  • A file reference from an FTP Adapter download operation






#Hand-On Practice : 


Use Case : Lets develop one simple APP DRIVEN ORCHESTRATION integration which can take some JSON inputs and that inputs will get send as an attachment in email notification in XML format.


Top view of integration which we are going to develop :



Lets see the steps in detail :

Step 1 : Crate one APP DRIVEN ORCHESTRATION by giving Integration a meaningful name. 

Select any REST Trigger connection and configure the adapter as shown below -



  • Enter a meaningful name and then click Next



  • Give a meaningful endpoint's Resource URI (I have given /employeeDetail), Select Action = POST, Select REQUEST , RESPONSE options to configure. Click Next
          [You can take reference from below image]



  • Configure the Request Sample JSON Payload window by entering below JSON and then click Ok.Click Next
{
  "Employee" : {
    "EmployeeDetail" : [ {
      "Name" : "Amit",
      "Id" : "01"
    }, {
      "Name" : "Rohit",
      "Id" : "02"
    } ]
  }
}


  • Configure the Response Sample JSON Payload window by entering below JSON and then click Ok.Click Next
{
"Message" : "Success"
}


  • REST adapter configuration completed.Click Done.


STEP 2 : Now add Stage File Action and configure the adapter as shown below 


  • Enter a meaningful name , click Next


  • Configure the Stage File Action parameters window as given below :
    • *Choose Stage File Operation : Write File
    • *Specify File Name : enter any meaningful name (I have given "Employee.xml")
    • *Specify Output Directory : enter any meaning directory path (I have given "/EmployeeDetail")

  • In this window select XML Schema (XSD) Document.Click Next


  • Download the below schema file and choose the same file 


  • Stage File Action configuration completed. Click Done.

  • Open the mapper to map the value


  • Do the one to one mapping as shown in below image. Make sure to add For Each in mapper.Click Validate and close the mapper.




STEP 3 : Add Notification Action in the flow and configure it as shown in below steps


  • Enter the basic details -- *FROM, *TO EMAIL ids, *Subject , *Body and then click "+" icon of attachments 
Knowledge :๐Ÿ‘€
You can configure the approval email address to use in the FROM field on the notifications page that is accessible from Settings → Notifications.




  • Drag and drop the *FileReference element inside the expression box. Click Validate and Close.


  • Again click Validate and Close.


STEP 4 : Edit the response mapper of integration and just hardcode "Success" message as a final integration response.

[as shown in below image]

  • Click Validate and close.



STEP 5 : Enable Tracking for the integration



  • Click Save and Close the integration . Integration is ready to TEST.



UNIT TESTING : - 

  • Activate the Integration

  • Click RUN icon (as shown in below image)

  • Pass the below JSON as Input Payload and then Click TEST
{
  "Employee" : {
    "EmployeeDetail" : [ {
      "Name" : "Ramlal",
      "Id" : "01"
    }, {
      "Name" : "ShyamLal",
      "Id" : "02"
    },{
      "Name":"Ramabai",
      "Id":"03"
    } ]
  }
}


  • You can see "Success" response in downward response window.
  • Now check your email. You have received one email notification with payload as shown below :
    • Email Notification along with attachment


    • Attachment payload with the data which we have sent as input



Thank you :)


14 comments:

  1. Thanks for the blog .It was working fine. Getting mail with attachment.

    ReplyDelete
  2. thank for the blog. it is very useful information to learn OIC

    ReplyDelete
  3. Thanks for the blog, it is helping me in learning OIC

    ReplyDelete
  4. Excellent blog, Keep posting bro, Thanks a lot. God Bless You Dear

    ReplyDelete
  5. Good stuff, Kabir.

    Do you know on how to add attachemnts conditionally? E.g. I've created seperate generic integration for Error handling and passing fileReference to it and map it for attachment purpose in notification. But If it is empty ( so I do not want to attach anything ) it wouldn't send an email.

    ReplyDelete
    Replies
    1. Read File --- >IF Data Available --> Trigger Email Notification
      |
      ELSE-->Do not Trigger Notification

      Delete
  6. is there any way to ad "CC" in the notification

    ReplyDelete
    Replies
    1. i don't think CC option is available in email notification, we can configure FROM & TO only

      Delete
  7. How can I do multiple attachments in notification?

    ReplyDelete
  8. I meant, how to multiple files dynamically? Lets say SFTP has n number of files, I need to send all files as an attachments in notification.

    ReplyDelete
    Replies
    1. Just click on '+' icon present in Attachment Box and add all the 'FileReference' which you want to send attachment in notification

      Delete

If you have any doubts, Please let me know.

close