Strange behavior regarding saving documents

lock
push_pin
done
Besvarat
4

Hi,

We have a major problem regarding saving documents for a company, its a bit of a "come and go" issue that has escalated for the last few days.

The problem is that NSDocumentAgent saves the wrong document, and directly after its saved, it says that the document has been checked out by another user, (that does not have anything to do with the sale, or customer, or even country)

We have the exact same code in multiple enviroments, but, its only happening for this customer.

They are using Webtools, and SO for documents.

The code

NSListAgent listAgent;
Byte[] TheFileInByte = decodeBase64(getCgiVariable("base64"));
NSDocumentTemplate documentTemplate = listAgent.GetDocumentTemplate(346); 
NSContact contactEntity;
contactEntity.SetContactId(MyContact.toInteger());
NSPerson personEntity;
if(personId != "")
  personEntity.SetPersonId(personId.toInteger());

NSSale saleEntity;
DateTime now;
NSDocumentAgent documentAgent;
NSDocumentEntity documentEntity = documentAgent.CreateDefaultDocumentEntity();
documentEntity.SetName(saleName + '.docx');
//documentEntity.SetHeader('Abax-OrderProposal-v' + NewVersion.toString());
documentEntity.SetHeader(saleName);
documentEntity.SetContact(contactEntity);
documentEntity.SetPerson(personEntity);
documentEntity.SetSale(saleEntity);
documentEntity.SetDate(now);
documentEntity.SetDocumentTemplate(documentTemplate);
NSAssociateAgent associateAgent;
documentEntity.SetAssociate(associateAgent.GetAssociate(assId.toInteger()));

NSDocumentEntity FUSO = documentAgent.SaveDocumentEntity(documentEntity);
DocId = FUSO.GetDocumentId();
NSStream stream;
stream.SetStream(TheFileInByte);
documentAgent.SetDocumentStreamFromId(DocId, stream);

It crashes with the following message:
NetServerException: NetServer exception: Service call Document.SetDocumentStreamFromId failed

Document ID 2487527, extref is locked and not checked out to current user Checked out by <another user>

But, the document is created, and, the content in the file is something else, in this specific case, a quote from 34 days ago, for another customer, another sale and has nothing in common with the document created, or hasnt been opened or modified since it was created.

And, we have verified that the base64 that comes in is in fact the document we wanted to save.

Anyone have any experience or ideas regarding this?
Regards
Pär Pettersson

15. okt. 2024 | 11:39 fm

Allt Svar (4)

Does this customer use SharePoint as document library and the others not? Or is this a difference between Online and Onsite customer?

15. okt. 2024 | 11:53 fm
Just default SO as document library.
And we have multiple customers running the same code, both online and onsite, and sharepoint and SO document library, so it does not seem to be related to that im afraid
15. okt. 2024 | 11:55 fm

Hi Pär,

I suspect problem is around here and the possibility that there may be more than one with the same name...

documentEntity.SetName(saleName + '.docx');

Have the script always been like this, or could it have changed around August this year? You have my email address with a SOS id :)

16. okt. 2024 | 01:59 em

Margrethe is right, its been running fine for a few days now.

And, it makes sense, since this customer pretty much always have the same heading in their sales, and therefore we havent noticed it at other customers.

Thanks ALOT

 

22. okt. 2024 | 08:25 fm

Lägg till svar