Rule scripting in FlexiCapture 11 -> count pages per Document Set

  • 71 Views
  • Last Post 2 weeks ago
  • Topic Is Solved
Melisa Uy posted this 3 weeks ago

Hi,

 

I have a requirement to count the number of pages per Document Set.

In my current Document Definition, I am creating alot of document set, on Verification rule, I added this script:

 

Context.Document.Pages.Count

 

But this script will add all the pages. I need to check per document set.

 

So I was checking online and found this:

int subDocumentsCount = 0;
          int pagesCount = 0;
          IBatchItem asBatchItem = Context.Document.AsBatchItem;
          IBatchItems items = asBatchItem.ChildItems;

          foreach (IBatchItem item in items) 
          {
              if ( item.Type == TBatchItemType.BIT_Page ) 
              {   pagesCount ++;  } 
              else if( item.Type == TBatchItemType.BIT_Document ) 
              {   subDocumentsCount ++; } 
              else 
              {
                  Context.CheckSucceeded = false;
                  Context.ErrorMessage = "Unknown type of element in set";
               }
          }
          Context.Field("Field").Text = subDocumentsCount.ToString() + " " + pagesCount.ToString();


However, this is code snippet for FlexiCapture 12.
We are still using version 11

Is there a similar library?

Thanks!

Order By: Standard | Newest | Votes
Reinhard posted this 3 weeks ago

Hello Melisa,

I don't understand what you mean by "document set". To you mean a batch?

Cheers

Reinhard

Melisa Uy posted this 3 weeks ago

Hey Reinhard,

 

Sorry , I meant Document Section. See attached screenshot

So basically, I need to check Section 1 (T&C) must have 5 pages

SEction 2 (Annexure) must have 2 pages

 

I believe it is possible, since on the web verification I can see page 1/5, 2/5, 3/5 and so on.

I just need to know which object to access or is there a workaround?

 

 

Thanks!

Attached Files

Reinhard posted this 3 weeks ago

Hello Melisa,

this is a script, which takes the pages of a batch coming via email. If the document source file name contains the string "invoice" is found, the page is assigned as document, othewise it is assigned as attachment:

using System;

IDocument invoice = null;

IDocument[] attachments = new IDocument[Documents.Count]; 

string info = "Fount attachment pages: ";

for (int i = 0; i < Documents.Count; i++)
{
    IDocument document = Documents[i];

    if (document.Pages[0].ImageSourceFileSubPath.ToLower().IndexOf("invoice") < 0)
    {
        attachments[i] = document;
    }
    else
    {
        invoice = document;
    }
    info = info + document.Pages[0].ImageSourceFileSubPath + "; ";
}
Processing.ReportMessage( info );

if (invoice != null)
{
    //if (Documents.Count > 1)
    //{
    //    invoice.Properties.Set("fc_Predefined:InvoiceAnnexPageIndex", invoice.Pages.Count.ToString());
    //}

    foreach (IDocument attachment in attachments)
    {
        if (attachment != null)
        {
            int count = attachment.Pages.Count;
            for (int i = 0; i < count; i++)
            {
                Batch.MovePage(attachment, invoice, 0, invoice.Pages.Count);
            }
        }
    }
}

This should hep you.

Cheers

Reinhard

Melisa Uy posted this 3 weeks ago

hi Reinhard,

 

what is "Documents.Count" for line 3 -> IDocument[] attachments = new IDocument[Documents.Count]; 

Reinhard posted this 3 weeks ago

Hello Melisa,

this script is part of the script for the workflow stage "Auswertung" in "batch type "email". We use 2 batch types in order to process documents arriving via email and documents arriving via scan client. We use the advanced workflow setting for the batch type email. In this workflow we have created a new stage "Auswertung" after the "Recognition" stage (see screen shot 1). In the script of this stage you have the import parameters "Documents" (see screen shot 2) and for this import parameter you can determine the number of documents in the batch via "Documents.Count". Sorry for the german screen shots. I hope you can understand it nevertheless.

Greetings

Reinhard

Attached Files

Melisa Uy posted this 2 weeks ago

oh I get it now :) Thanks Reinhard :)

 

I was thinking as much, for us we do a Database compare (values read on OCR against another system) and we created this workflow after verification.

 

Yeah thanks again! I think this will work nicely for me :)

 

Cheers!

Melisa Uy posted this 2 weeks ago

Hi Guys,

 

If anyone is interested, I was able to add this script rule on my DD.

Steps:

1) Go to Document Defintion > Edit

2) Double click pageNumber field

3) Navigate to Rules tab > New Rule

4) Paste this script:

//config
string currentSectionName = "Annexure";
int requiredPages = 2;
for (int i=0; i<Context.Document.Pages.Count; i++) {
   
    IPage p = Context.Document.Pages[i];
    string sectionName = p.SectionName.ToUpper().Trim();

    if( !string.IsNullOrEmpty(p.SectionName) && sectionName == currentSectionName )
        pageno++;   
}


if (pageno!=requiredPages) {
    Context.CheckSucceeded = false;
    Context.ErrorMessage = currentSectionName + " must have " + requiredPages.ToString() + " pages";
}

 

Hope this helps .

Attached Files

Melisa Uy posted this 2 weeks ago

 thanks again Reinhard! awesome man! It gave me loads of idea how to navigate thru FlexiCapture !

Close