Search code examples
xpagesxpages-ssjs

test if jpg file exists in other domino database


I'd like to make a fallback when displaying pictures out of a notes database. The notes database normally contains a pdf and a jpg version with the same name (except the extension) If the jpg picture exists I would like to display it , if not I would like to display the pdf using google drive

return "<embed src='https://drive.google.com/viewerng/viewer?embedded=true&url=https://demourl.pdf' width='500' height='375'></embed>"

So the question is : what's the best way to test if a picture exists in a notes document


Solution

  • You can create a view showing all design elements and then do a lookup if the required picture is contained in the database.

    Here is the required Lotus Script Code to modify a view for displaying all design elements in a NSF:

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    
    Set db = session.CurrentDatabase
    Set view = db.GetView("DesignElements")
    Set doc = db.GetDocumentByUNID(view.UniversalID)
    Call doc.ReplaceItemValue("$FormulaClass","32766")
    Call doc.Save(True,True)
    

    Just add a sorted column for "$TITLE".

    EDIT:

    Shameless copied from https://www.assono.de/blog/ye118wday-design-elements-views

    EDIT 2: If you just want to check for a existence of a file in a normal document, I suggest to create a view with two sorted columns. 1st column with DocumentUNID, 2nd with @AttachmentNames-Formula. Then you can do a lookup for the specific document / attachment.