Error: A name cannot contain character ' '

To help us find batches faster when troubleshooting issues, we created a custom workflow stage in our project that has a script to rename the batch based on Vendor Name and Invoice Number if they are found. The script is as follows:

var name_edited = "";
if (Documents[0].Field("Invoice Layout\\Vendor\\Name").Text != ""){
    var batchName = Documents[0].Field("Invoice Layout\\Vendor\\Name").Text + " - ";
    name_edited = batchName.Replace("'", "_").Replace(":", "_").Replace("/", "_").Replace("*", "_");
    Batch.Name = name_edited + "HF_ID" + Batch.Id;
}

if (Documents[0].Field("Invoice Layout\\InvoiceNumber").Text != ""){
    name_edited += Documents[0].Field("Invoice Layout\\InvoiceNumber").Text + " - ";
    Batch.Name = name_edited + "HF_ID" + Batch.Id;
}

Most of the time the script works when the Vendor and/or Invoice Number is found, but we are seeing a lot of the following errors and I am not sure how to change the script to fix the problem.

-1    2    12/14/2022 3:34:25 PM    System.Runtime.InteropServices.COMException (0x80004005): Error: A name cannot contain character ' '.    at ABBYY.FlexiCapture.IBatch.set_Name(String _name)    at Main.Execute(IBatch Batch, IDocuments Documents, IProcessingCallback Processing)

I would think that if the IF statements were not satisfied it would just name the batch like normal like HD_ID123456789, so I'm not sure why it thinks there would be an empty name. If anyone has any feedback it would be greatly appreciated.

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.