Archive

Posts Tagged ‘Attachment’

Notes: Attachments in Subforms

Mal wieder trieb mich Notes in den Wahnsinn, diesmal mit Attachments in RichText-Feldern.

Das Problem war, ich hatte einige Forms, welche im Grunde exakt gleich ausgesehen haben, daher mussten Subforms her.
Ich hatte in jeder Form eine Subform, welche das Layout abbildete und dann noch jeweils eine Subform für den Datenteil der jeweiligen Form und noch eine für die Attachments. Da die Attachments nicht in jeder Form auftauchen sollten, war die entsprechend computed.

Da war dann das Phänomen dass ständig unterhalb der Form noch die Attachments sichtbar waren, also nochmal separat aufgelistet wurden. Sehr nervig.
Normalerweise tritt dieses Phänoment nur auf, wenn das Dokument Attachments enthält, aber das Feld wo es drin liegt, ausgeblendet ist. Das war aber gar nicht der Fall.

Nach einigem hin und her probieren stand dann die Ursache fest. Das Problem war einfach, dass die Subform computed war. Scheinbar wird Notes intern erst dieser Mechanismus durchlaufen, also prüfen ob das RichText Feld da ist, wenn ja dann zeige es dort an, wenn nicht, dann zeig es unterhalb der Form an. Erst danach werden dann die Subforms berechnet. Von daher ist es vollkommen egal ob das Feld angezeigt wird oder nicht, Notes geht erstmal davon aus dass das Feld potentiell nicht angezeigt werden könnte und packt sie zur Sicherheit nochmal unter die Form. Wenn man die Subform so wie sie ist direkt einbaut funktioniert alles wie es soll. Statt der computed subform habe ich dann entsprechend Hide-When Formeln benutzt, dort tritt das Problem seltsamerweise nicht auf, die werden scheinbar vor dem Attachment Mechanismus berechnet.

Advertisements

Stumbling Stone: FileUpload-Control

Today I had a tiny problem. Not even a bug, only a small booby trap.

On my page, I had three FileUpload controls and one FileDownload control. It was specified that a user can upload a maximum of three attachments. Therefore I added a rendering condition to all FileUpload controls, which chekcs the number of attachments in the document.
WARNING: The formula @Attachments doesn’t seem to work properly. It seems like @Attachment only checks the backend-document. I want to know how much attachments were uploaded right now to constrain the possibility to upload something. The function “doc.getAttachmentList(‘feldname’).size()” saved my day.

The three controls are placed below another, the first will be hidden if there are thee attachments, the second if there are two and the last one if there is at least one attachment. All this linked to a refresh, which is fired when you delete one attachment, everything works fine.

However, I faced the effect, if I add 3 attachments at once, only two were saved. The attachment from the last FileUpload control was never saved.

Get ready for the reason:

Controls seem to be processed sequential, connected with an internal refresh. That means, the first control is processed and the file is uploaded -> new there is a refresh -> second control is processed, everything is fine, so the second attachment is uploaded -> there is a refresh again -> third control wants to be processed, but there is more than one attachment in the document, so the control is not rendered anymore, therefore, the third attachment goes to hell.

The solution is quite easy, you only have to reverse the order of the number of attachments in the render condition. That means, the first control should be hidden if there is more than one attachment, the second is hidden with two attachments and the third with three attachments. Because the controls are processed in order they are in the code, everything works fine.

Another interesting fact is, that if you have some mandatory fields or have another server-side validation on your form, attachments are uploaded when you click the save button. After that the validation yells. The backend document doesn’t get bothered, but in the frontend document, there are your attachments uploaded, yet. In the context of my problem above, this could be quite confusing, but if you know that fact you can work around that.

%d bloggers like this: