Check Part One to see how to create the model needed to Process a form.
Once your model has been created and published you are able to create an App or Flow that utilises it. Microsoft Flow is an extremely powerful way to use the Form Processor because it can automatically take newly submitted forms and create a record out of them.
To start, create a new Flow in and Solution and use the SharePoint trigger ‘When a file is created in a folder’ and add the folder where all new files will go. In this example the default Documents location is being used.
The next part calls the AI model using the ‘Predict’ action. Note: this action is only available to Flows created in a solution, so make sure you Flow was created as part of a Solution. Select the Model from your published models and then add the Request Payload in the format:
Replace the *FILE CONTENT* with the dynamic content ‘File Content’ from the trigger
Replace the *CONTENT TYPE* with the dynamic content ‘Content-Type’ from the trigger
Before you add the parse JSON action you need to run the Flow and get the response payload. This can be done a number of ways however to ensure you get the full payload add a temporary action that saves the response to SharePoint (in a separate folder to your trigger) and run the flow by adding a valid example of your PDF/Image to the triggering folder. This will then mean you can copy and paste the full response payload from the Predict action.
Now add the Parse JSON action and add the Response Payload variable from the Predict action. Click on Use Sample Payload to generate schema and paste in your copied payload from the previous step. You may notice that the first time you run this the Flow will fail due to the Parser expecting an integer but got a number. To fix this you must update all the keys with type ‘integer’ to type ‘number’. One way to fix this is to put the generated Payload Schema in a text editor and use replace all ‘integer’ with ‘number’, however, if you have any fields that contain the work ‘variable’ you will need to manually change these back after.
Next add the Create Record action for CDS and select the required entity. Now add the fields by selecting the values retrieved from the Predict action. The issue here is that all your values will be called ‘value’ in the Dynamic Content selection, this means you will not know which value is the field you want.
In order to get around this issue you can type out the full expression, in this case the expression is “body(‘Parse_JSON’)?[‘predictionOutput’]?[‘label’]?[‘Last Name’]?[‘value’]”.
Note: Once you save and close the Flow and then reopen it the expression will revert back to the Dynamic Content just saying value. Then simply change [‘Last Name’] to each different field name.
You can repeat the previous step for each record created. If you want to create a reference between two of the records, for example have a contact as a primary contact, you must create the Contact first and then when making the account add it as the Primary Contact using the dynamic content.
Once you have finished creating your Flow you can start testing it by adding files to the chosen document location in SharePoint. This Flow and Model will greatly reduce the time taken to enter data into your system, after you have gotten this working smoothly you can begin enhancing it even more for your business needs.