Best way to get user who opened a document / batch

  • 3.3K Views
  • Last Post 2 weeks ago
richfish posted this 08 December 2016

Hi All,

I'm forcing every batch to go through verification, I need to get the username of the person that opened the batch. I need to get the username even if the document wasn't opened or any rules run.

At the moment I have code on event handler 'after document rule checked':

string verifiedField = "Invoice Layout\\VerifiedBy";

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

userName = Regex.Replace(userName,".*\\\\(.*)", "$1", RegexOptions.None);

if (userName != "fcservices" && userName != "Administrator")

{

Document.Field( verifiedField ).Text = userName;

}

Which works fine but the event handler doesn't always fire if the document has no verification or errors.

Same as if using standard rule script, it doesn't always run.

Would be nice to have a batch opened event handler that could update document definition fields.

Have also tried batch event handlers but they can't modified document fields or batch parameters.

Have also tried service field 'last editor info' but that will populate the service account running the processing station if no changes have been made to document.

Any help appreciated.

Cheers

Richard

 

Order By: Standard | Newest | Votes
Ekaterina posted this 13 December 2016

Hello

You may use the “after batch opened” event handler: Appendix > Using scripts in ABBYY FlexiCapture > Scripts for customizing processing stages > Types of scripts > Event handlers > Batch opened/closed

 

You may go to the project > project properties > event handler tabs > select “after batch opened” string > add the script.

  • Liked by
  • richfish
richfish posted this 13 December 2016

Hi Ekaterina,

Thanks for your suggestion. Where would I store the information?

Batch Open Event Handler has read only access to IBatch fields and 'Internal fields of batch documents and pages are unavailable'. When I tried this previously I had errors trying to set a batch parameter or document definition field contents.

Thanks

Richard

richfish posted this 13 December 2016

Example, if I use:

Batch.Properties.Set(verifier, userName);

To try and set a batch parameter I get error when opening batch:

Error in the 'After batch opened' event..... Cannot modify object data from this script.

If I try and use

Document.Field("\\Invoice Layout\\VerifiedBy").Text = userName;

To try and set a field on the document definition I get 'The name document does not exist in the current context'.

If I try and use

for ( int i = 0; i < Batch.Documents.Count; i++ )

{

Batch.Documents[i].Field("\\Invoice Layout\\VerifiedBy").Text = userName;

}

I get 'Error in the 'After batch opened' event..... Cannot modify object data from this script.'

Thanks

Richard

 

richfish posted this 13 December 2016

I notice that the help file mentions:

 Appendix > Using scripts in ABBYY FlexiCapture > Scripts for processing interface events > Event handlers > On Open Document 

And that it suggests that you have access to IDocumentEditor Read/write but I can't see where to add these scripts?

Can you help?

Thanks

Richard

richfish posted this 13 December 2016

Can't get that method to work either, so using:

if (userName != "fcservices" && userName != "Administrator")

    {

    //Context.Field( verifiedField ).Text = userName;

    DocumentEditor.Document.Field("Invoice Layout\\VerifiedBy").Text = userName;

    }

On interface event 'On Document Open' gives error 'Cannot modify object data from this script.'

 

Ekaterina posted this 14 December 2016

Hello, Richard

I suggest to use the following scenario:

1. Create the service field. In the “Data source” tab select “batch registration parameter” source. Named the registration parameter.

2. Create the batch with that registration parameter. Assign it a value.

3. Open Project properties window, general tab, press “edit tool” button. Add “On Task Window Create” event, edit the script, which changes the registration parameters value.

richfish posted this 10 March 2017

Hi Ekaterina,

Had to come back to this again. I've managed to setup as suggested which is great and seems to populate the batch registration parameter, thank you. I'm concerned about what happens if this fails. I cant see a way of making the registration parameter mandatory and also cant see a way of letting the user edit it. So I thought about making a second field on the document and copying the registration parameter into it. I could then set that to not be blank and allow the user to edit it.

The issue is that the script rule doesn't copy the parameter into the field when the document is opened from the task screen.

Is it possible to copy the batch parameter into another field on the document from the 'On Task Window Create' script?

I had thought something such as:

foreach (string document in TaskWindow.Batch.Documents)

{

TaskWindow.OpenDocument();

//Code here to update fields

}

But i get 'No overload for method 'OpenDocument' with 0 arguments and not sure what 'OpenDocument' needs to be able to identify the document to open?

Also thought about 'On Document Open'

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

userName = Regex.Replace(userName,".*\\\\(.*)", "$1", RegexOptions.None);

 

if(DocumentEditor.Document.Batch.BatchTypeName == "Swift Invoices Test" || DocumentEditor.Document.Batch.BatchTypeName ==  "Swift Invoices Test")

{

DocumentEditor.Document.Field("Invoice Layout\\VerifiedBy").Text = userName;

}

But this doesn't seem to work, I don't get any errors. Where are these scripts logged? Any advice appreciated.

 

Tanks

Richard

Ekaterina posted this 13 March 2017

Hello,

Please note that the OpenDocument method should take the IDocument argument OpenDocument( document : IDocument ) 

as described in the Developer's Help article: Appendix > Using scripts in ABBYY FlexiCapture > Scripts for processing interface events > Objects > ITaskWindow. 

When you use the TaskWindow.Batch.Documents collection in foreach, the IDocument document, not the string document, should be used. To display diagnostic messages you may use IFlexiCaptureTools object, especially FCTools.ShowMessage(string) method. To get detailed analysis of your project and workflow please contact your regional support.

Dawid M posted this 2 weeks ago

Hello!

Could you please tell me how can i get currently logged user on WEB verification? When i tried the above it did not work at all or did return only service account running processing station, not real user working with document.

Thanks in advance,

Dawid Majdański

Close