Search

What the Quote?

"...and me without a mountain lion."

Thorin Blair

"Nothing in life is free... except for my fist in your face."

Laura Hearron

"this is what, my third, fourth black president? What do I care?"

Colin MacDonald

« Quote of the day | Main| Example of using LS:DO to connect Domino to other systems »

SnTT: Unlink individual design elements from a template

Category show-n-tell thursday
By request, here's a SnTT (whoa, it's actually Thursday for once) demonstrating how to programmatically unlink any design elements tied to a specific template (while leaving intact any other element-level inheritance):

Public Function UnlinkElements(dbTarget As NotesDatabase, Byval templateName As String)
    Dim linkedElements As NotesNoteCollection
    Dim element As NotesDocument
    Dim noteId As String
    
    Set linkedElements = dbTarget.CreateNoteCollection(False)
    Call linkedElements.SelectAllDesignElements(True)
    Let linkedElements.SelectionFormula = {$Class = "} & templateName & {"}
    Call linkedElements.BuildCollection()
    If (linkedElements.Count > 0) Then
        Let noteId = linkedElements.GetFirstNoteId()
        While (Len(noteId) > 0)
            Set element = dbTarget.GetDocumentByID(noteId)
            Call element.RemoveItem("$Class")
            Call element.Sign()
            Call element.Save(True, True, True)
            Let noteId = linkedElements.GetNextNoteId(noteId)
        Wend
    End If
End Function


Enjoy...

Comments

Gravatar Image1 - Thanks, Andre, that's good to know. I've gotten in the habit of signing any elements modified via a NotesDocument handle regardless of the modification to avoid the "this document has been modified or corrupted since signed" warning... which goes away, of course, the next time the element is manually saved, but tends to spook some developers. Makes sense in retrospect, though, that this wouldn't be an issue when modifying unsigned items.

Gravatar Image2 - I know... 12 minute TTL? Must be losing my touch. Time to dig out the ol' FrogPad again.

{ Link }

I think it's in my trunk.

Gravatar Image3 - Based on one quick, not conclusive test, the $Class item is not signed. Therefore, it shouldn't be necessary to re-sign the design element. Doing so can complicate matters if the new signature is different.

At the least, check whether the original item is signed, and only update the signature if it was.

Gravatar Image4 - It took you long enough to get this done and posted!! Good grief... Emoticon

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)