Skip to main content

I built a learning instance using Document Automation to extract data from a PDF document. For one of the field “Reference” i would like to add couple of leading zeros to the value depending on a condition:

If value extracted for this field starts with 4, i would like to simply add 2 leading zeroes to the value.  I created a Field Rule with a condition “Starts with” and used the “set value” option in the “THEN perform the following actions” section but not sure how i can set dynamic values. I basically need to concatenate the extracted value and 2 zeros in the front.

I’m not sure how we can set dynamic values here. Any help is appreciated. Thanks in advance.

Hi ​@Srini 6969,

 

In Field Rules for Document Automation, the Set Value action only accepts a static value. It doesn’t allow referencing the original extracted value or applying string operations like concatenation directly inside the rule.


You need to handle this in the Bot logic after extraction, not inside the learning instance.
 

  1. Extract the document using your learning instance as usual.
  2. In your Automation Anywhere bot, after you get the extracted fields (usually as JSON or variables), apply a string manipulation step:

Check if Reference starts with 4.
If yes, prepend "00" to it.

 

Use String: If condition and String: Concatenate actions.
Pseudocode:

If ($Reference$, 1) = "4"   

     Set $Reference$ = "00" + $Reference$

End If

In AA, you can do this using:

String: Substring to get the first character.
String: Concatenate to add "00" in front.

 

 

Or, Use Python or JavaScript inside AA

Add a Python script or JavaScript snippet in your bot:

ref = $Reference$
if ref.startswith("4"):
   ref = "00" + ref
return ref


Document Automation is designed for data extraction, not for post-processing logic. All formatting or conditional transformations should happen in the bot after extraction.


@Srini 6969 Excellent answer, ​@Padmakumar as usual!

If you want to avoid the scripting languages, the String package actions will also allow you to prepend the zeros at the beginning of the string.