- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2026 03:22 AM
Hi @Sneha KH
This behavior is expected in Service Portal and usually happens because attachments are not handled automatically like platform forms.
In a Service Portal widget, you must explicitly control record creation and attachment upload. If either step is missed or done in the wrong order, the record or attachment will not be saved.
Below is the approach that works correctly.
Approach
Attachments can only be saved after a record exists.
So the flow must be:
Create the record in the widget Server Script
Capture the generated sys_id
Return the sys_id to the Client Script
Upload the attachment using table name and sys_id
Server Script
(Create the custom table record first)
(function () {
if (input && input.action === 'create') {
var gr = new GlideRecord('u_custom_table'); // custom table name
gr.initialize();
gr.u_short_description = input.short_description;
var sysId = gr.insert();
data.sys_id = sysId;
data.table = 'u_custom_table';
}
})();Client Script
(Upload attachment after record is created)
api.controller = function ($scope, spAttachmentManager, spUtil) {
var c = this;
c.attachments = [];
c.submit = function () {
c.data.action = 'create';
c.data.short_description = c.short_description;
c.server.update().then(function (response) {
var sysId = response.data.sys_id;
var table = response.data.table;
if (sysId && c.attachments.length > 0) {
spAttachmentManager.uploadAttachments(
table,
sysId,
c.attachments
).then(function () {
spUtil.addInfoMessage('Record and attachment saved successfully');
});
}
});
};
};HTML
(File upload field)
<input type="file" multiple ng-files="c.attachments" class="form-control">*************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh