โ06-03-2023 10:59 AM
I have a pipeline that outputs a json file that I would like to reformat into a payload for a Slack webhook app. Itโs for an outlist and the json output list a personโs fullName with startDate and endDate and duration for the absence. The payload would have a header and footer that the data needs to be between.
{
โabsenceTypeโ: โVacationโ,
โendDateโ: โFri, 19 Mayโ,
โstartDateโ: โFri, 19 Mayโ,
โfullNameโ: โKimberly Smithโ,
โdurationโ: 7
},
{
โabsenceTypeโ: โVacationโ,
โendDateโ: โMon, 22 Mayโ,
โstartDateโ: โTue, 23 Mayโ,
โfullNameโ: โKimberly Smithโ,
โdurationโ: 14
},
{
โabsenceTypeโ: โVacationโ,
โendDateโ: โFri, 26 Mayโ,
โstartDateโ: โFri, 26 Mayโ,
โfullNameโ: โKimberly Smithโ,
โdurationโ: 7
},
I want data like the above to be transformed into a payload to look like the following which includes the header and footer that I mentioned. Please note how multiple day absences have different text than single day absences and although this sample data only shows one person one persons absences, there will be multiple people:
{
โchannelโ: โ#snl-out-listโ,
โblocksโ: [
{
โtypeโ: โsectionโ,
โtextโ: {
โtypeโ: โmrkdwnโ,
โtextโ: โAbsences within the next 7 days:โ
}
},
{
โtypeโ: โsectionโ,
โtextโ: {
โtypeโ: โmrkdwnโ,
โtextโ: โ :palm_tree: Kimberly Smith*โ
}
},
{
โtypeโ: โsectionโ,
โfieldsโ: [
{
โtypeโ: โmrkdwnโ,
โtextโ: โโข Fri, 19 May:7 hours:Vacationโ
}
]
},
{
โtypeโ: โsectionโ,
โfieldsโ: [
{
โtypeโ: โmrkdwnโ,
โtextโ: โโข Mon, 22 May to Tues, 23 May:14 hours*:Vacationโ
}
]
}
{
โtypeโ: โsectionโ,
โfieldsโ: [
{
โtypeโ: โmrkdwnโ,
โtextโ: โโข Fri, 26 May:7 hours:Vacationโ
}
]
}
],
โusernameโ: โMy Botโ
}
Solved! Go to Solution.
โ06-05-2023 03:25 AM
Hey @swright
I was able to generate the expected o/p but what to do with the first two elements, I couldโve hardcoded it but I didnโt cause I think you are getting that data dynamically from somewhere.
Iโve attached the sample pipeline with the expression in it.
Test_Expression_2023_06_05.slp (5.6 KB)
I hope this helps ๐
Cheers
โ06-04-2023 05:14 AM
I successfully managed to get the pipeline functioning by utilizing FTP snaps and a Unix Snap to execute a Perl script I developed for the transformation process. However, I am still curious about achieving the same outcome within Snaplogic itself. I attempted using Script snaps with Javascript or Python, but encountered numerous errors that I believe were caused by how the Script snaps implement those languages.
It seems that I frequently find myself needing to rely on external tools instead of utilizing Snaplogic for such processing tasks. I would appreciate exploring how this could have been accomplished within Snaplogic, both with and without the use of a Script snap.
I uploaded sample files with what is to be transformed (sample_incomming_data.json) and what it is to be transformed to (sample_output_payload.json).
sample_incomming_data.json (4.3 KB)
sample_output_payload.json (7.2 KB)
For reference I also uploaded the Perl script that I wrote that successfully does the transformation (transform.pl.txt). This uses the Perl JSON module so I had to install it:
sudo yum install perl-JSON
transform.pl.txt (2.7 KB)
Scott
โ06-05-2023 03:25 AM
Hey @swright
I was able to generate the expected o/p but what to do with the first two elements, I couldโve hardcoded it but I didnโt cause I think you are getting that data dynamically from somewhere.
Iโve attached the sample pipeline with the expression in it.
Test_Expression_2023_06_05.slp (5.6 KB)
I hope this helps ๐
Cheers
โ06-06-2023 06:00 PM
Hey @Soni37
Thatโs an exceptional solution! It functions flawlessly and exhibits a remarkable elegance in its relative simplicity. I didnโt think it could be done with so little code and so few snaps!
I initially tried utilizing the Group By N snap, but I couldnโt quite grasp how to utilize the output to achieve my desired outcome. Your inclusion of โgroup.mapโ in the mapper function was the missing piece that I needed!
Thanks and regards,
Scott
โ06-06-2023 10:54 PM