Can someone help me with LS to remove attachments? Nothing is working

I’m having trouble removing attachments in LS. The files are uploaded on my xpage, and the postsave event from the xpage calls an agent to extract the files and remove them from the document. However, none of my attempts are working, and I don’t know why. The document is definitely saved in the LS sub. I’ve tried the following…

didn’t work, so then I tried using this after extracting all the files…

didn’t work, so then I tried using this…

didn’t work, so then I tried…

didn’t work, so then I tried something else I found in the forum…

no luck… I’m running out of options and spent WAY too much time on something that is supposed to be fairly straightforward. I don’t get errors with the above approaches, but when I look at the doc properties, I can see that the files are still there.

Can somebody point out the obvious that I’m missing?

Subject: Try

Print out filestr and see what the value is. Also if you run the agent manually does it work? Does the signer of the agent have the correct right? sess.commonusername will signer of the agent

Subject: Yes, the script saves the doc…

I added a print statement just before the save, so I know it’s saving each time. This one really has me stumped - but I’m sure I’m missing stupid.

Subject: SOLVED

Thank you for all your suggestions - sometimes it just takes another set of eyes… my script was working with two document variables and I was saving the wrong one after the attachments were removed.

Rookie mistake, but apparently, I still need to be humbled after 15 years of development.

Subject: Here are my results…

My code looks now like this…

I had the save command further down, but added it here to see if it made any difference. My doc properties looked like this before I ran the code

The console shows the results…

but, when I check doc properties, nothing has changed. It shows 5 SuppAttach fields and 6 $File fields.

Subject: Is this a MIME Document?

Subject: try this …

Dim rtitem
Set rtitem = doc.GetFirstItem( “Body” )
If ( rtitem.Type = RICHTEXT ) Then
ForAll o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
Call o.ExtractFile ( |c:\attachments| & o.name )
Call o.remove
Call doc.save(true, false)
End If
End ForAll
End If

Subject: Files are attached with an xpage upload control

I’m not doing anything to change the attachment type. I’m just using the upload control “out of the box”.

Subject: Save document?

The Remove method of the NotesEmbeddedObject class always work for me. Do you save the NotesDocument afterwards, it is not showing that in your code sample.

Add a doc.Save() after o.Remove and see what happens.