Hiya @mnikitina
I am trying to run some code to retrieve the first attachment of a newly created/edited item and them update the item with the details of the attatchment (I can't seem to get it to work using PnP):
fd.spSaved(function(result) {
fetch(_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Inventory')/items(" + result.Id +")/AttachmentFiles",
{
method: 'GET',
headers: {
'Content-Type': 'application/json;odata=verbose',
'Accept': 'application/json;odata=verbose'
}
})
.then(response => response.json())
.then(function (data) {
var attachmentURL = data.d.results[0].ServerRelativeUrl;
var noAttachmentURL = '/sites/COREaaS-OrderSystem/SiteAssets/no-image-icon.png';
if (attachmentURL){
console.log(attachmentURL);
//update item
inventoryItems.getById(fd.itemId).update({
Photo: {
Description: Item Photo,
Url: attachmentURL
},
Photo_x0020_URL: attachmentURL
})
} else {
//No picture - update item
inventoryItems.getById(fd.itemId).update({
Photo: {
Description: Item Photo,
Url: noAttachmentURL
},
Photo_x0020_URL: noAttachmentURL
})
}
})
});
This works in Edit view if I put it in the fd.beforeSaved, but of course, if they change the attachment, it doesn't work, I was thinking of using your attachment control, but the client can't have their data on anyone else's server. When I do it in the fd.Saved I get an network error in the console.
Is there any way I can update the attachment?
I know I can use flow or a workflow, but they take a long time to run, Javascript is just so much quicker!
Thanking you in advance!