cancel
Showing results for 
Search instead for 
Did you mean: 

FSM Business Rule to send all attachments of the activity via email to the responsible

DAcker
Contributor
0 Kudos
2,295

Hi all,

I want to create a business rule in FSM that sends all attachments from the activity and the corresponding expense via email to the responsible of the activity triggered by a certain workflow-step.

I achieve everything in the BR except that dynamically all (multiple!) attachments get attached to the email. So I tried to write a for-loop in javascript, but it unfortunately does not work. I just get one (the first) attachment attached to the email.

See details to the business rule:

Trigger: (see screenshot)

Action: Send Mail (see screenshot)

for Attachment ID I tried:

${var i; for (var i = 0; i < attachment.length; i++) {attachment[i].id;}}

for File Name:

${var i; for (var i = 0; i < attachment.length; i++) 
{attachment[i].fileName;}}_${technician.firstName}_${technician.lastName}__${serviceAssignmentStatus.createDateTime}_${serviceCall.code}.${var
 i; for (var i = 0; i < attachment.length; i++) 
{attachment[i].type;}}

The validation check is successful but if I execute the business rule, just 1 attachment is attached (see screenshot below) and no matter if I insert multiple attachment placeholder with the same code or with other starting points for i (always i=0 or i=1,2,3...) or just one placeholder.

Any ideas? This shoud be possible or isn't it?

Thanks so much & best regards

Deborah

DAcker
Contributor
0 Kudos
ttraeger

kennst du dich mit Business Rules aus - wahrscheinlich nicht in der Tiefe, oder doch? 😉


0 Kudos

the js shell dnt allow native loops.

You can try this:

${var endString = '';attachment.forEach(function(element) { endString += element.id + " ";}); endString;}
View Entire Topic
christian_hauck
Advisor
Advisor

Hi Deborah, regarding your question in your comment below my answer above, which is related to copying of attachments: Meanwhile there is a specific way for attachments, how you could copy an attachment to another object.

It should work like shown in the example below:
First read the attachment dto via Data API within action ‘FSM Webhook’ and afterwards use another action ‘FSM Webhook’ to copy the attachment to another object, which is specified in the body.

An important little thing is to parse the lastChanged attribute of the attachment, like done in the URL of the second action ‘FSM Webhook’, which is needed to have the right value of the date converted in the right format.

Best Regards,
Christian


DAcker
Contributor
0 Kudos

Hello christian.hauck ,
thanks for your feedback! Really appreciated.
I tried to test the API Request first in Postman before I get it up and running via FSM BR.
I did not find the FSM API Package on SAP API Hub. The documentation in the help portal does not described it in detail. Unfortunaltey no example or explainations for the POST request on attachment API.
https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_data_api/attachment-api.html?locale=en-US

If I try to do the copy action (as in your screenshot), I get the error "CA-27". See screenshot.
What do I need to change?

The last changed timestamp of the attachment I am trying to copy is from 31th August 2020. But I am trying to create a new attachment, so I dont really understand the conflict...

Best regards, Deborah

Yanik_Kurzawski
Participant
0 Kudos

Hey Deborah,

I've already implemented the BusinessRule as Christian showed and it works for me.

But I've had the same problem as you. Unfortunately I'm not sure anymore what the problem was because it was already a while ago. I think it could be an authentification error. If I validate my BR the "user=..." isn't actually an the UUID of the User it is the id shown for users in the admin portal (user=${user.id}).

If you implement this into a business Rule I could help and compare it with my Rule if this would help you.

Greetings
Yanik

DAcker
Contributor
0 Kudos

Hey Yanik yanik_kurzawski
I changed it to the user ID visible in the admin portal. However, I still get the same error.
It would be great to compare it to your Business Rule. Can you export it?
Thanks!
Deborah

Yanik_Kurzawski
Participant
0 Kudos

Hey deborah.albrecht2

sure. You can message me and tell me where to send it.

Greetings
Yanik

DAcker
Contributor
0 Kudos

Hi yanik_kurzawski ,
the SAP chat is not working... I tried it with 2 browsers. However, please send it to d.acker@gebhardt-group.com.
Thanks!
I will compare it and hopefully find a solution that I can share here....

DAcker
Contributor
0 Kudos

Hi all,
my issue was that I tried to send to current timestamp as lastChanged with the POST request.
I thought this timestamp will be set in the update on the database.
This understanding is wrong. If you perform the update you have to send the lastChanged unix timestamp of the last change on the attachment. Then it works!
A bit strange, I think... But, now it works. I could copy the attachment via API request from Business Partner to Activity.
Thanks a lot for your help!
Greetings, Deborah