script is taking too much memory while archivied an document via CUSTOM API

Hi,

i try to achive an document (pdf) so SuperOffice.FileStream is an Base64 of an PDF file. If i use it with very small documents, than it works. If i would import an PDF Dokument (539KB), than i get the following message: ""EjScript::RunTimeException: Script is taking too much memory: 30084Kb"".

The script works unit the line "documentAgent.SetDocumentStream(createdDocumentEntity, stream, true);" here i get the errormessage.

i tested it in SOD. Is there another way to import the file, without storage the file in web?

Here ist the code:

Byte[] fileStreamByte = decodeBase64(fileStream);

//Dokument erzeugen
NSDocumentAgent documentAgent;
NSDocumentEntity documentEntity = documentAgent.CreateDefaultDocumentEntity();
//Ersteller
User user = getActiveUser();
Integer associateId = user.getValue("associateId").toInteger();
NSAssociateAgent associateAgent;
NSAssociate associate = associateAgent.GetAssociate(associateId);
documentEntity.SetAssociate(associate);
//Header setzen
documentEntity.SetHeader("TEst");
//Filename setzen
documentEntity.SetName("blalblabla.pdf");
//Template setzen
NSDocumentTemplate documentTemplate;
documentTemplate.SetDocumentTemplateId(168);
documentEntity.SetDocumentTemplate(documentTemplate);
//Datum setzen
//documentEntity.SetDate(datum);
//Person setzen
NSPersonAgent personAgent;
NSPerson person = personAgent.GetPerson(720);
documentEntity.SetPerson(person);
if (person.GetContactId() != 0) {
//Contact vorhanden
NSContactAgent contactAgent;
NSContact contact = contactAgent.GetContact(person.GetContactId());
documentEntity.SetContact(contact);
}
//Verkauf vorhanden, setzen
NSSaleAgent saleAgent;
NSSale Verkauf = saleAgent.GetSale(49);
documentEntity.SetSale(Verkauf);
//Dokument erstellen und speichern
print("tester");
NSDocumentEntity createdDocumentEntity = documentAgent.SaveDocumentEntity(documentEntity);
NSStream stream;
stream.SetStream(fileStreamByte);
documentAgent.SetDocumentStream(createdDocumentEntity, stream, true);
Integer documentId = createdDocumentEntity.GetDocumentId();

 

RE: script is taking too much memory while archivied an document via CUSTOM API

Hi,

in the forum i found the following article: https://community.superoffice.com/en/developer/forum/rooms/topic/superoffice-product-api-group/customer-service/simple-crmscript-that-triggers-memory-error-in-sod/

I change the import, the import of 500KB documents works now, but an 2,3MB mail doesn't work i get the message:

EjScript::RunTimeException: Script is taking too much memory: 17676Kb

here i the code from so import

#setLanguageLevel 3;
//Dokument erzeugen
NSDocumentAgent documentAgent;
NSDocumentEntity documentEntity = documentAgent.CreateDefaultDocumentEntity();
User user = getActiveUser();
Integer associateId = user.getValue("associateId").toInteger();
NSAssociateAgent associateAgent;
NSAssociate associate = associateAgent.GetAssociate(associateId);
documentEntity.SetAssociate(associate);
//Header setzen
documentEntity.SetHeader("testheader");
//Filename setzen
documentEntity.SetName("fileName.pdf");
//Template setzen
NSDocumentTemplate documentTemplate;
documentTemplate.SetDocumentTemplateId(164);
documentEntity.SetDocumentTemplate(documentTemplate);
//Person setzen
NSPersonAgent personAgent;
NSPerson person = personAgent.GetPerson(720);
documentEntity.SetPerson(person);
//Dokument erstellen und speichern
HTTP http;
NSStream stream = http.getAsStream("https://so.scandtrack.com/upload/169,871,102.msg");
NSDocumentEntity createdDocumentEntity = documentAgent.SaveDocumentEntity(documentEntity);
documentAgent.SetDocumentStream(createdDocumentEntity, stream, false);

 

best regards

 

Mike

Av: Mike Behrendt 14. jan 2020