on 2020 May 29 2:29 PM
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
Request clarification before answering.
Hi Deborah,
the documentation on https://help.sap.com/viewer/fsm_admin/Cloud/en-US/send-email.html contains a json file with an sample business rule which could be uploaded to your list of business rules. This sample rule shows an example, how to send an email with several attachments. I think it should work, if you try to do it like in this example (which looks similar to your case).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi christian.hauck ,
thanks for your reply! This is working. I did it the same way as in the sample business rule and it works. That's great! 🙂
I have another question, but very similar use case: I want to copy the attachments from the business partner to the activity on activity creation. Background to this requirement is, that I just can set in the READ authorization for Attachments to ALL or OWN or Attachments in relation to assigned activities. I saw the new option with organization unit. Because the attachments are not automatically assigned to any org units, I cannot use this option at all (for the moment).
If I set the authorization to ALL attachments the performance is very bad... a lot of attachments are downloaded, that the technician don't need. The app for the technician is restricted to see just their own activities. However, our dispatchers want to attach certain documents / information on business partner level. E.g. forms that need to be filled out in order to enter the production hall where the repair of the equipment is happening. If I set the authorization to OWN attachment, these attachments on business partner level, which are added from the dispatcher, are not visible. That is my problem. Therefore, I thought I can do a workaround and copy the attachment of the business partner to the activity on activity creation and then change the authorization to OWN attachments and related to assigned activities.
Is this possible to do with a business rule? As it was working to send multiple attachments via email to somebody. I changed the business rule action to "create object" instead of "send email". The business rule works and does not show an error. But the attachment is corrupt / cannnot be opened. I cannot see any fileContent in the Attachment table, which I can set. Therefore, I see the attachment with its correct fileName, but it cannot be opened. Here a screenshot of the business rule:


Thanks very much for your feedback.
Best regards, Deborah
Hello Deborah,
currently we are investigating from development side whether we could provide it in a way that fits the standard.
I'll let you know soon.
Additional remark: within BRs we are not able to deal with binary content. So we are are seeking for a solution to copy them in one step instead of first reading the origin and afterwards creating the new attachment.
Best regards, Christian
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
Hi All.
I've made a Business Rule to copy attachments from Activity to ServiceCall. Similar case as you above. One error leading thing i found is, that if you take the "lastChanged" from a variable, e.g:
https://de.coresuite.com/api/data/v4/Attachment/${attachment.id}/actions/copy?dtos=Attachment.18&las...attachment.lastChanged).format('x')}&user=${user.id}
the unix formated date is rounded. Even if you extend it afterwards, its wrong.
unix formatted lastChanged Date from variable = 1686841104000
unix formatted lastChanged Date from FSM Webhook JSON = 1686841104664
This leads to the error mentioned above. So the only valid way, is to parse the lastChanged Date from a Webhook.
Maybe this clarifies for someone.
Best Regards
Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
deborah.albrecht2:
Sorry für meine späte Antwort, ich schaue hier fast nie rein. Von BRs habe ich schon Ahnung, nur genau von so einer nicht. Wir haben aktuell was das versenden von Anhängen angeht nur BRs im Einsatz die die Checkout reports direkt an den Kunden versenden (sprich direkt in der Build Report Aktion).
Die Sent Email aktion haben wir bei uns zumindest im Zusammenhang mit Anhängen nicht im Einsatz.
Grüße
Tobias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 12 | |
| 11 | |
| 8 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.