# New record attachments are not sent from Portal

This issue is caused by the fact that the record users add attachments to in the portal is not in fact the record being integrated by Unifi. It's a temporary record which ServiceNow will then move the attachments from to the requested item/target record of a record producer at a later time.

An issue arises here though as a Unifi create message can be triggered before ServiceNow moves the attachments. If this happens then Unifi will not send the attachments.

To get around this issue we can trigger a new ServiceNow event to be fired when Unifi sends a create message. This will then give time for the attachment to be added to the request. We will use a script action to then force update any attachments on the requested item, thus triggering Unifi as if the attachment was just added.

Follow these steps:

* Create a new event, say, `unifi.send.portal.attachments.on.create`
* Create a new Script action, which runs on the above new event, with the following code:

```javascript
var attachments;
attachments = new GlideRecord('sys_attachment');
attachments.addQuery('table_sys_id', '=', current.sys_id);
attachments.query();

while (attachments.next()) {
  attachments.setForceUpdate(true);
  attachments.update();
}
```

* Modify the create message to trigger the event, i.e. in the Source to stage script of the CreateRequest message, add the following code below the autogenerated scripts:

```javascript
gs.eventQueue('unifi.send.portal.attachments.on.create', source, '', '');
```

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sharelogic.com/unifi/3.1/troubleshooting/attachments/new-record-attachments-are-not-sent-from-portal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
