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

Question

Question

How to force Quick Fields to assign a template when barcode scanning has failed

asked on February 6, 2015

I have built a session to scan a document with the "Barcode" as a token.  The session has a script to process the barcode as "a text key" to retrieve data from a database. It will then insert returned values to the fields of a template and assign a default document name with a returned value. When the barcode scanning fails to recognize the pattern due to overlapped lines or stains "on" the barcode, I will get a popup text field to collect the "text key" to retrieve the data from the backend. However, the document will be processed as an "identified document", so the fields are not filled (but the "document name" is filled with a returned value).

How can I force Quick Fields to assign a "DocumentClassName" to my template with script?

Here is the scenario:

Quick Fields version: 8.3

Language: C#

Code examples:

1.            

string strBarcode = (string) e.Document.Tokens.GetTokenValue("BARCODE 1");

2.         

if (string.IsNullOrEmpty(strBarcode))

{

  // when barcode is not detected, get strBarcode from "this.TextboxValue" and then send to the database

}

3.

 if (string.IsNullOrEmpty(e.Document.DocumentClassName))
 {

//get a message when the template is not applied (Worked. Did get this message.)

  e.API.ShowMessageBox("no documentname...");

 

//- the codes below indicated different attempts to "assign" a template. (Did not work.)
//            e.Document.DocumentClassName("MYTEMPLATENAME");
//            e.Document.Tokens.ChangeToken("Barcode 1", strBarcode);
//            e.Document.DocumentClassName.Replace("", "MYTEMPLATENAME");
 }

4.

no error message when the session ran.

the query returned a set of value but only the "document name" is filled.

5.

the file got scanned into the "unidentified documents" folder.

6.

Processing Summary:
1 page(s) processed.
0 identified document(s).
    0 MYTEMPLATENAME (0 pages)
1 unidentified document(s).
0 error(s) occurred.
Pages Per Minute: 3

7.

a document with a "clear" barcode will result in a file with the right template format and all the fields are filled with returned values.

 

Thank you very much. Any help is appreciated.

 

0 0

Replies

replied on February 9, 2015

Which event are you running this script on? Do you have a document class called "MYTEMPLATENAME"?

Why not just leave your document class without any identifications and make the document length 1?

0 0
replied on February 9, 2015

The process is the regular class "script 1" from Quick Fields script editor. The event is "Document.Processd.After". The main process is to use "barcode" as a token. If the barcode is scanned in properly, it then retrieves data from the database based on the characters converted from the barcode. If the barcode has noise, it doesn't get scanned, a popup box will ask for the barcode code.

Pretend my template is "MYTEMPLATENAME". The template has "Field A", "Field B"...

After the process, the system will retrieve data from a database based on the "barcode" key and insert values to "Field A", "Field B"... of the template, AND, use a returned value (pretend to be the exact value of the "field a") to be the default document name.

The result of the script: when the barcode is clear, everything works. The file is processed with the template and gets all the template fields filled. However, when the barcode scan fails, the popup will take my input and apply the "field a" value as the default document. However, "Field A", "Field B"... get nothing and the template is not applied.

I used "--e.Document.DocumentClassName("MYTEMPLATENAME");--" in my code hoping that I can "force" the document to be processed as "MYTEMPLATENAME", but it didn't work.

Here is the output (the first part is a "barcode run", the second is through input):

Barcode 1[Type=Code 128]: 20140012345
Created document of class MYTEMPLATE.
Added page 1.
rdr is not null
strBarcode = 2014-0012345
Processing Summary:
1 page(s) processed.
1 identified document(s).
    1 MYTEMPLATE (1 pages)
0 unidentified document(s).
0 error(s) occurred.
Pages Per Minute: 8


Barcode 1 :
Created an unidentified document.
Added page 1.
rdr is not null
strBarcode = 2014-0011111
Processing Summary:
1 page(s) processed.
0 identified document(s).
    0 MYTEMPLATE (0 pages)
1 unidentified document(s).
0 error(s) occurred.
Pages Per Minute: 4

What is the correct code to manually assign a template in script? Thank you for helping. I did not get an error during the process, so I don't know what to look for.

(I actually don't know what " leave your document class without any identifications and make the document length 1" means.)


Big thanks!

0 0
replied on February 9, 2015 Show version history

Document classes and templates are not the same thing. It sounds like you named your document class after your template and that's causing confusion. You can assign documents to existing document classes, not make new ones on the fly.

I expect your Barcode process is in the Identification section of your document class? If you take it out and change the document length (under Properties for the document class) to 1, each page that comes into Quick Fields will create a new document. You can then add a Barcode process under Page Processing and use its token to trigger the database lookup. If barcode finds a value on the page, then you will get the lookup automatically. If it doesn't the user can fill in the value after scanning and re-trigger lookup.

If you still want to use scripts, you'll want to set your script to run on the Document Unidentified event since you only want to change the document class when identification fails. Then you want to run the following code to re-assign the document type from unidentified to the existing document class:

e.ReassignDocument("Document Class Name Goes Here");

 

0 0
replied on February 9, 2015 Show version history

Thank you for your reply. I will try your suggestion and let you know the result.

(On the other hand, I cannot assign the page to "1" because I don't know how many pages I will have for "1" document. I expect a "barcode" will break files into different documents. I have to use script to process because this is not a simple "lookup". I have to call a stored procedure which has some complicate calculation and reformatting.)

0 0
replied on February 9, 2015

Hi, Miruna: I just tried. There is not a method called "ReassignDocument". Not under "e" nor under "e.document" either. Is it from "Interop.LFSO83Lib"? Thanks!

0 0
replied on February 9, 2015

You need to move the script to the "Document Unidentified" event. The "after document processed" event has nothing to do with identifying documents which is what you are trying to do.

Side note: It's not clear to me how you expect this to work when barcode is not read. Quick Fields appends pages to the current document until a new page is identified. But if your barcode is not read, then no new document will be started. So unless you pop up the message box after each page scanned, there's no way your script will ever run unless the very first page scanned is the one that fails.

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

Sign in to reply to this post.