I used the "Recognize text in an image or a PDF document" action to read text from invoice PDFs I upload to SharePoint. I then initialized and set a Purchase Item variable (as a string) that includes all of the Purchase Items to search each invoice PDF for. If any of these words are included in the documents, I then added a "Create File" SharePoint action that adds those words to the file name. (The search uses the OR function, meaning I don't it to look for the presence of ALL words, but rather any of these words).
Earlier in the flow, before the "Recognize text in an image or a PDF document" action, I created another variable, New File Name. that includes outputs from three other parts of the PDFs and creates a file naming convention using those outputs. I'd initially tried to include the Purchase Item in this first variable, but the flow wasn't recognizing it for some reason. I believe it's because the Purchase Item doesn't have a clear label on each invoice. My workaround for this was to use the "Recognize text in an image or a PDF document" action to search for these words instead, and then add them to the New File Name variable.
However, this unfortunately also didn't work. The Purchase Item variable I created remains empty, even though I can see the "Recognize text in an image or a PDF document" action has accurately extracted text from the PDFs in its outputs. My flow does accurately rename each invoice the New File Name variable, though. It just doesn't include the Purchase Item at the end of it. I'm not sure how to resolve this and would greatly appreciate any guidance!! Below are the inputs of the actions and variables mentioned above. Let me know if I can provide any other information that'd be helpful in troubleshooting.
- Recognize text in an image or a PDF document:
- body('Get_file_content_using_path')
- Initialize variable New File Name:
-
replace(replace(replace(
concat(
outputs('Extract_information_from_documents')?['body/responsev2/predictionOutput/labels/FieldA/text'],
'_',
outputs('Extract_information_from_documents')?['body/responsev2/predictionOutput/labels/FieldB/text'],
'_',
outputs('Extract_information_from_documents')?['body/responsev2/predictionOutput/labels/FieldC/text']
), '.', '-'), '/', '-'), '\', '-')
- Initialize variable Purchase Item:
-
trim(concat(
if(contains(coalesce(outputs('Recognize_text_in_an_image_or_a_PDF_document')?['body/responsev2/predictionOutput/fullText'], ''), 'ACD215'), 'ACD215-', ''),
if(contains(coalesce(outputs('Recognize_text_in_an_image_or_a_PDF_document')?['body/responsev2/predictionOutput/fullText'], ''), '4wX2rRH553'), '4wX2rRH553-', ''),
if(contains(coalesce(outputs('Recognize_text_in_an_image_or_a_PDF_document')?['body/responsev2/predictionOutput/fullText'], ''), '875snToWPF31Ne'), '875snToWPF31Ne-', ''),
))
- Create File:
-
concat(
variables('NewFileName'),
trim(concat(
if(
contains(toLower(trim(coalesce(outputs('Recognize_text_in_an_image_or_a_PDF_document')?['Text'], ''))), 'ACD215'),
'ACD215-',
''
),
if(
contains(toLower(trim(coalesce(outputs('Recognize_text_in_an_image_or_a_PDF_document')?['Text'], ''))), '4wX2rRH553'),
'4wX2rRH553-',
''
),
if(
contains(toLower(trim(coalesce(outputs('Recognize_text_in_an_image_or_a_PDF_document')?['Text'], ''))), '875snToWPF31Ne'),
'875snToWPF31Ne-',
''
)
))
)