Ignore mapping if empty

hi there,
how can I ignore the mapping if I am not getting any values? example in the below screenshot for the record, there’s no attachment so mapping should not happen. for this example since no attachement its failing in the downstream snaps.


Thanks
Manohar

Hi @manohar ,

You can use Filter snap before the mapping and filter out the records that do not have attachment.

BR,
Marjan

Hi @manohar,

If I understand correctly, you don’t need those fields in the final result, if their value is null ?
If that’s the case, you can try the following expression:

sl.ensureArray($attachments.attachment.filter((v,k)=>v!=null))

and map the Target path as $attachments only.

Let me know if this helps,
Bojan

Hi @bojanvelevski , that’s right.

But wondering with this approach, how can I avoid the target portion?

Thanks
Manohar

Thanks @marjan.karafiloski but what @bojanvelevski is said is what I was looking for.

Is it possible to show in a mapper how it should look like. I exported the mapper portion of my pipeline.
mytransformation_2022_10_21 (1).slp (68.3 KB)

Thanks
Manohar

@bojanvelevski @marjan.karafiloski , wondering if you have any pointers based on how my input is?

Thanks for you help,
Manohar

Hi @manohar ,

You can also use Router snap, where you will check if there is attachment, like:

$attachments.get(‘attachment’) != null

After that, you can use two different mappers, one without the attachment and one with it.

BR,
Marjan

1 Like

You cannot impact the attachments array directly in one mapper, since you have another mappings happening on the same level in the target object.

What you can do though, is add another Mapper that will serve as a filter. The mapper uses the Mapping root to go down to the attachment object and filter out the “type”,“text” and “intent” fields if they are null.

mytransformation_2022_10_25.slp (69.7 KB)

Let me know if this helps,
Bojan.

Thanks @bojanvelevski wondering how can I remove “attachments” node as well, if they are coming as null.

I went with this solution for now but trying to reduce no. of snaps to get to that

Thanks
Manohar

Hi @manohar

I think it’s possible in a mapper snap with this expression and as target path nothing.
I had this question also before to delete the fields that are empty and had this solution below

Expression: jsonPath($,“$…[?(value == {}) ]”)
The expressions checks the paths if they are null and then delete them if so. After that you need a next mapper snap that checks all the fields of null values and delete them.

Example in the pipeline with mapper snap below

The reason for two snaps is I think that you first need to check the values inside the array and after that you can check the higher parent for null values. I think you will understand if you check the pipeline.

If there is a more efficient way I am happy to hear.
Test_Pip_V1.3_2022_10_26 (1).slp (6.2 KB)

Thanks @JensDeveloper if I go with that, then it would drop other required fields, although they are null. so it’s just some fields like the attachment (as it’s actually a related record) need to be dropped.

Thanks
Manohar

You can directly replace Copy + Filters with a Router. You can accomplish this by updating the expression in the Mapper(Filter) snap. Check pipeline below:

mytransformation_2022_10_26.slp (69.8 KB)

I would recommend the router version with proper mappings afterwards.

Regards

1 Like

Hi @manohar ,

As I wrote in my post above, you can use the Router and proper mappings after them.