You are viewing limited content. For full access, please sign in.

Question

Question

Deleting arbitrary annotations with SDK

asked on November 29, 2013

Workflows can only delete annotations added by activities that appear above (http://www.laserfiche.com/support/webhelp/workflow/9.0/en-us/LFWorkflow.htm#cshid=Resources/Activities/Selecting%20Annotations.htm)

 

Does SDK support deleting arbitrary annotations, namely stamps with a given name ?

 

Thanks in advance,

 

Lou

0 0

Answer

APPROVED ANSWER
replied on December 3, 2013 Show version history

 The following untested snippet shows the general idea.

// This code snippet will loop through all the pages of the current entry and
// will delete all annotations that are applications of a particular stamp.
// I'm assuming the ID of the stamp is BAD_STAMP_ID.
const int BAD_STAMP_ID = 42;

// this.Entry refers to the entry being processed during this activity. We assume
// it's a document.
ILFDocument doc = (ILFDocument)this.Entry;
doc.LockObject(Lock_Type.LOCK_TYPE_WRITE);
// Retrieve all the object that represents the collection of pages, and obtain
// a listing of all stamp annotations. For each stamp annotation, obtain the
// ILFPage reference that represents the page the annotation is on and then
// look up the annotation object so we can query the stamp ID. If it's equal to
// BAD_STAMP_ID, delete the annotation.
ILFDocumentPages pages = doc.Pages;
ILFAnnotationListing anns = doc.GetAllAnnotations(Annotation_Type.ANN_STAMP);
for (int i = 1, rows = anns.RowCount; i <= rows; i++)
{
    int pageNum = (int)anns.DatumByColType(Annotation_Column.ANNOTATION_COLUMN_PAGE_NUM);
    int itemID = (int)anns.DatumByColType(Annotation_Column.ANNOTATION_COLUMN_ITEM_ID);
    ILFPage page = pages.Item(pageNum);
    ILFStampAnnotation ann = (ILFStampAnnotation)page.GetAnnotationByID(itemID);
    if (ann.StampID == BAD_STAMP_ID)
        page.RemoveAnnotation(ann);
}
// Be sure to unlock when you're done.
doc.Dispose();
4 0

Replies

replied on December 2, 2013

Yes, using the SDK you can write code which can enumerate annotations and stamps and individually delete the objects you select. Before I write any source code, I'd need to know the context. For example, do you already know the document ID or have some other reference to the document? Or do you want to iterate through all of the documents in the repository? Is this from Workflow, and if so, which version?

1 0
replied on December 3, 2013

Hello Michael,

 

Client is using Workflow 9.0.2.244 and the document of interest appears to be the starting entry.

 

Hope that helps...

1 0
APPROVED ANSWER
replied on December 3, 2013 Show version history

 The following untested snippet shows the general idea.

// This code snippet will loop through all the pages of the current entry and
// will delete all annotations that are applications of a particular stamp.
// I'm assuming the ID of the stamp is BAD_STAMP_ID.
const int BAD_STAMP_ID = 42;

// this.Entry refers to the entry being processed during this activity. We assume
// it's a document.
ILFDocument doc = (ILFDocument)this.Entry;
doc.LockObject(Lock_Type.LOCK_TYPE_WRITE);
// Retrieve all the object that represents the collection of pages, and obtain
// a listing of all stamp annotations. For each stamp annotation, obtain the
// ILFPage reference that represents the page the annotation is on and then
// look up the annotation object so we can query the stamp ID. If it's equal to
// BAD_STAMP_ID, delete the annotation.
ILFDocumentPages pages = doc.Pages;
ILFAnnotationListing anns = doc.GetAllAnnotations(Annotation_Type.ANN_STAMP);
for (int i = 1, rows = anns.RowCount; i <= rows; i++)
{
    int pageNum = (int)anns.DatumByColType(Annotation_Column.ANNOTATION_COLUMN_PAGE_NUM);
    int itemID = (int)anns.DatumByColType(Annotation_Column.ANNOTATION_COLUMN_ITEM_ID);
    ILFPage page = pages.Item(pageNum);
    ILFStampAnnotation ann = (ILFStampAnnotation)page.GetAnnotationByID(itemID);
    if (ann.StampID == BAD_STAMP_ID)
        page.RemoveAnnotation(ann);
}
// Be sure to unlock when you're done.
doc.Dispose();
4 0
replied on May 17, 2023

Could this be easily updated to delete ALL annotations on a specific document? We have documents that have annotations added to them as they go through an approval process. When the document is fully approved, before it gets put in its final resting place, we would like to delete all annotations currently applied to it to make sure it is clean.

0 0
replied on May 17, 2023

Yes*.
 

* the code above is using LFSO, so you'd have to convert it to use RepositoryAccess since LFSO is no longer available in Workflow. After that, you can remove the line that checks for the "bad stamp" and iterate through all the annotations you read from the doc.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.