Community

Transfer data between documents in a batch

Hi, I have the following scenario:
Documents to be scanned (sold Fishing Licenses) are received in groups from various vendors, with attached Sales Report. We scan the Sales Report as a "Batch Header" and all associated Licenses into individual batches. The Batch Header document contains 3 data fields which must be entered on each subsequent License document during Verification (data entry).

On the License document definition I've added fields to accept the Batch Header data, and attempted to script (C#.net) copying a value from a Batch Document field. I tried scripting a Rule; then tried a Recognition script; then tried a Custom Action; all attempts have failed. The Rule and Custom Action script produce the attached error message (see image):

System.Runtime.InteropServices.COMException (0x80004005): Cannot access other documents from rule check script.
at ABBYY.FlexiCature.IBatch.get_Documents()
at Main.Execute(IRuleContext Context)

The script (Rule and Custom Action) follows below... the idea is to:
1) get the field's Document (thisDoc)
2) get the document's batch (batch)
3) get the batch's Documents (batchDocs)
4) get the first document in batchDocs (batchHeader)
5) get the text value of a field in batchHeader (batchVendor)
6) assign the batchVendor value to a field: thisDoc.Field("DocVendor")

using System.Diagnostics;

//if (!Debugger.IsAttached)
//{
// Debugger.Launch();
//}
//Debugger.Break();

IDocument thisDoc = Context.Document;
IBatch batch = thisDoc.Batch;
IDocuments batchDocs = batch.Documents;
IDocument batchHeader = batchDocs[0];

string batchVendor = batchHeader.Field("VendorNumber").Text;

Context.Field("DocVendor").Text = batchVendor;

The error message seems to indicate the failure is at the point where it tries to get the batch's collection of Documents...

Anybody successfully done something like this? Is it possible? The support vendor is telling me he doesn't think it will work this way, but we might figure out a workaround hack. My question(s): does the concept above make sense? Shouldn't it work? Am I missing something, can I make it work?

Thanks,
Woody
0

Comments

4 comments

  • Avatar
    Aleksey Nikitin
    I tried scripting a Rule; then tried a Recognition script; then tried a Custom Action; all attempts have failed.

    It's because you can't modify other documents in the batch from this scripts.
    If you are using Distributed version of FC10, a batch processing script should be used. You should add a custom stage based on batch processing script in your Project settings. (See Project -> Settings menu item and in Workflow tab you should select Advanced workflow -> Add automatic stage -> Script tab) Here you should write your script which will run in a loop on documents and copy field values from 'header' document to other documents.
    If you are using Standalone version of FC10, using user command will be a more appropriate approach. (See Project-> Settings menu item and in Stage tools tab for Verification stage you should add button to skin and add event "On User Command"). The script concept is similar to distributed case but additionally you should identify button by "CommandId" argument and open other documents for editing (ITaskWindow - OpenDocument and CloseDocument methods)
    0
  • Avatar
    jwdvorak
    Thanks, Aleks... you're absolutely right, this works perfectly.

    I'd gotten a clue that this was the solution from abbyyusa.com support team, but their advice wasn't quite as detailed as yours. I initially made the mistake of creating a Document processing script stage, instead of Batch processing, and it didn't work (same error as the other script methods). Fortunately, while flailing again (trying to "move" the script to an external assembly, in order to debug), I happened to notice the Document/Batch script option... changed it to a Batch script, made the necessary modifications to code, and *poof*! It worked...

    Another issue, a bit off topic... when I tried to move the script to an external assembly: I compiled (built) the CustomCode.dll, and attached it to the Project (.NET references); I then added a "using CustomeCode;" directive in the Batch script, and added a statement to call the DoSomething(Batch, Documents, Processing) method from the assembly. The script doesn't compile, it complains the DoSomething() method does not exist.

    I've used the same technique to attach the CustomCode.dll assembly to Document Definitions, and used it to perform Rule validation of document fields, so I'm mystified why it's not working here?

    Thanks again for being so helpful.
    Woody

    0
  • Avatar
    jwdvorak
    Another issue, a bit off topic... when I tried to move the script to an external assembly: I compiled (built) the CustomCode.dll, and attached it to the Project (.NET references); I then added a "using CustomeCode;" directive in the Batch script, and added a statement to call the DoSomething(Batch, Documents, Processing) method from the assembly. The script doesn't compile, it complains the DoSomething() method does not exist.


    Never mind that... I'd simply forgotten to instantiate a CustomCode object in the script, and then call the method using objCC.DoSomething() syntax. Duh... it's working.

    I'm experiencing another anomaly, though, in using the external assembly... as mentioned in prev post, I'd attached the CustomCode.dll to individual Document Def's. Now that I've attached CustomCode.dll to the Project, I expected I could remove the .Net Reference from the Document Def's; my hope / intent was to streamline updating the assembly, since the reference is at a higher hierarchical location. Unfortunately, when I remove the reference from the Doc Def's, the Rule script fails to find it.

    Just an FYI, for anybody else who might experience this gotcha... I reexamined the Help document describing use of external assemblies, and learned I was mistaken about their use in a Rule script - the reference must be made at the Doc Def level, not at the Project.

    Thanks again,
    Woody

    0
  • Avatar
    Irene
    Hi, the reason of such behavior of the software is the following:

    When you are adding an external assembly in the project properties, you just create a shared external assembly that is possible to be added to the Document Definition or Batch Type properties. This shared assembly will be added to newly created Batch Types automatically. But if you want to add this shared external assembly to the Document Definition or existing Batch Type, you need to do the following:
    1. On the .Net References of Batch Type or Document Definition properties, click Add…
    2. In the Add Assembly dialog box that opens select Shared assembly.
    3. Select the assembly name from the Reference list.
    can find more detailed information in our ABBYY FlexiCapture 10 Help AppendixUsing scripts in ABBYY FlexiCapture 10External Assemblies.

    Best regards,
    Irene
    0

Please sign in to leave a comment.