Loading
Intelligent Document Reader
Содержание
Выбрать фильтры

          Результаты отсутствуют
          Результаты отсутствуют
          Ниже приведены некоторые советы по поиску.

          Проверьте орфографию ключевых слов.
          Воспользуйтесь более общим поисковым запросом.
          Выберите несколько фильтров для расширения области поиска.

          Выполните поиск по всей справке Salesforce.
          Sample Flow to Extract and Store Text in Records

          Sample Flow to Extract and Store Text in Records

          Create a flow in Flow Builder by using Intelligent Document Reader Flow actions to extract text from uploaded documents or content document IDs. Get the active OCR template details, and then use Apex to create records for storing the extracted text.

          Required Editions

          Available in: Lightning Experience
          Available in: Automotive Cloud, Consumer Goods Cloud, Education Cloud, Financial Services Cloud, Health Cloud, Manufacturing Cloud, Media Cloud, Net Zero Cloud, Nonprofit Cloud, Public Sector Solutions. View product and edition availability.
          Intelligent Document Reader is available with the Intelligent Document Reader add-on license.
          User Permissions Needed
          To open, edit, or create a flow in Flow Builder: Manage Flow
          1. From Setup, in the Quick Find box, enter Process Automation, and then select Flows.
          2. Click New Flow.
          3. Select Screen Flow, and then click Create.
            Note
            Note You can select a flow type that suits your requirement.
          4. Create the required resources.
            1. To store the content document ID, create a variable of Text type with the label as Content Document ID.
              If one or more content document IDs are entered, this variable stores a content document ID. If one or more documents are uploaded, this variable stores the ID of the content document currently in a loop that’s added to repeat the operation for each content document ID.
            2. To store the OCR template ID currently in a loop that’s added after the Fetch Active OCR Templates action, create a variable of Text type with the label as OCR template ID.
          5. For users to upload documents or specify content document IDs, add a Screen element, and enter the label and API name for the element.
            1. For users to upload documents, drag the File Upload component to the screen canvas, and enter the label and API name for the component.
            2. For users to specify content document IDs, drag the Text component to the screen canvas, and enter the label and API name for the component.
          6. To determine whether documents were uploaded or content document IDs were specified, add a Decision element.
            1. Enter the label and API name for the element.
            2. Add the condition as content document ID equals true.
            If the condition is met, content document IDs were specified. Else, documents were uploaded.
          7. If content document IDs were specified, add an Assignment element.
            1. Enter the label and API name for the element.
            2. Set the Content Document ID variable’s value from the specified content document IDs.
          8. If documents were uploaded, repeat the operation for the content document ID associated with each uploaded document.
            1. Add a Loop element, enter the label and API name for the element, and select the variable that stores the content document IDs of the uploaded files.
            2. Add an Assignment element, enter the label and API name for the element, and set the Content Document ID variable’s value as the ID of the current item from the loop.
          9. To initiate text extraction for the uploaded documents, add an Action element.
            1. From the Category section, select Intelligent Document Processing.
            2. Find and select the Initiate Text Extraction action.
            3. Enter a label, an API name, and a description for the action.
            4. Specify the text variable that stores the content document IDs.
            5. If necessary, specify the range of the pages of the document that you want to extract information for.
            6. If necessary, specify the name of the OCR service that extracts text from the document.
            7. Click Done.
          10. To show the details of the documents that text extraction has been initiated for, add a Screen element, and enter the label of the API name for the element.
            1. To show the extracted information, drag the Text component to the screen canvas, and enter the label of the API name for the component.
            2. In the Text component, insert the resource that stores the output of the Initiate Text Extraction action.
              The output contains the OCR document scan result ID and page number for each page for the specified content document ID or IDs that the text extraction is initiated for.
          11. To get the text extracted from the uploaded documents, add an Action element.
            1. From the Category section, select Intelligent Document Processing.
            2. Find and select the Fetch Extracted Text action.
            3. Enter a label, an API name, and a description for the action.
            4. Specify the text variable that stores the content document ID.
            5. If necessary, specify the range of the pages of the document that you want to fetch the extracted information for.
            6. Click Done.
          12. To show the details of the text extracted from documents, add a Screen element, and enter the label of the API name for the element.
            1. To show the extracted information, drag the Text component to the screen canvas, and enter the label of the API name for the component.
            2. In the Text component, insert the resource that stores the output of the Fetch-Extracted Text action.
              The output contains the extracted text, bounding box coordinates, and the extraction confidence.
          13. To get the details of the active OCR templates in the Salesforce org, add an Action element.
            1. From the Category section, select Intelligent Document Processing.
            2. Find and select the Fetch Active OCR Templates action.
            3. Enter a label, an API name, and a description for the action.
            4. Click Done.
          14. Repeat the operation for each OCR template ID fetched by the Fetch Active OCR Templates action.
            1. Add a Loop element, enter the label and API name for the element, and select the output of the Fetch Active OCR Templates as the variable.
            2. Add an Assignment element, enter the label and API name for the element, and set the OCR Template ID variable’s value as the ID of the current item from the loop.
          15. To show the details of all the active OCR templates, add a Screen element, and enter the label of the API name for the element.
            1. To show the active OCR templates, drag the Text component to the screen canvas, and enter the label of the API name for the component.
            2. In the Text component, insert the resource that stores the output of the Fetch Active OCR Templates action.
              The output contains the details of all the active OCR templates.
          16. Save your changes, and then activate the flow.
          17. After you get the details of the extracted text and the active OCR templates, use Apex to store the extracted text in the target object fields that are mapped in the corresponding templates.
          Example
          Example

          Let’s assume that these results are the OCR document scan result details.

          {
            "keyValuePair" : [ {
              "key" : {
                "confidence" : 85.27661895751953,
                "text" : "a Employee's social security number",
                "label" : null,
                "language" : null,
                "polygon" : [ {
                  "x" : 0.30966568,
                  "y" : 0.15110396
                }, {
                  "x" : 0.47195905,
                  "y" : 0.15096205
                }, {
                  "x" : 0.4719769,
                  "y" : 0.16660306
                }, {
                  "x" : 0.30968243,
                  "y" : 0.16674507
                } ]
              },
              "value" : {
                "confidence" : 85.27661895751953,
                "text" : "123-45-6789",
                "label" : null,
                "language" : null,
                "polygon" : [ {
                  "x" : 0.3385959,
                  "y" : 0.16764826
                }, {
                  "x" : 0.43139917,
                  "y" : 0.16756704
                }, {
                  "x" : 0.43141937,
                  "y" : 0.18554746
                }, {
                  "x" : 0.33861536,
                  "y" : 0.18562874
                } ]
              }
            }],
            "sdkresponse" : {
              "statusCode" : 200,
              "successful" : true
            },
            "version" : "1.0"
          }

          Use Apex to store the extracted text in the target object and its record type fields that are mapped in the corresponding OCR templates.

          Here’s a sample of the way in which you can invoke the Apex code to create a Case record for storing the extracted text details.

          public class TransformDocumentDetailsRequest {
             	@InvocableVariable (required=true)
              public String key;
              
              @InvocableVariable (required=true)
              public String targetObjectApiName;
            
              @InvocableVariable (required=true)
              public String contentDocumentID;
              
              @InvocableVariable(required=true) 
              public string origin; 
              
              @InvocableVariable(required=true) 
              public string status; 
              
              @InvocableVariable(required=true) 
              public string subject; 
                  
          }
          public class TransformDocument {
              private static final String KEY_VALUE_PAIR = 'keyValuePair';
              private static final String TEXT = 'text';
              
              @InvocableMethod(label='Create Case Record' description='Creates a Case Record using the extracted values fetched from the document')
              public static void transform(List<TransformDocumentDetailsRequest> requestList) {
                  // Get the OcrDocumentScanResult (ODSR) response for document uploaded in the flow
                  List<OcrDocumentScanResult> odsrResponse = getOdsrResponse(requestList[0].contentDocumentID);
                  
          		// Pass key for which value should be fetched
                  String value = getValue(odsrResponse, requestList[0].key);
                  System.debug('key and value fetched: key:'+ requestList[0].key + ' value: ' + value);
                  
          		// Add appropriate required fields here. These particular fields are for Case Record. 	
          		Map<String, String> requiredFields = new Map<String, String>();
                  requiredFields.put('Status', requestList[0].status);
                  requiredFields.put('Subject', requestList[0].subject);
                  requiredFields.put('Origin', requestList[0].origin);
                  saveExtractedValuesInTargetObject(requestList[0].key, value, requestList[0].targetObjectApiName, requiredFields);
              }
          
              /**
              * This method returns the extractedValues for the given content Document ID
              */ 
              private static List<OcrDocumentScanResult> getOdsrResponse(String ContentDocumentID) {
                  List<OcrDocumentScanResult> ocrScanResults = [SELECT ExtractedValues FROM OcrDocumentScanResult WHERE ContentDocumentId =: ContentDocumentID];
                  return ocrScanResults;
              }
              
              /**
              * This method returns the value corresponding to the key in the response.
              * The response contains separate OcrDocumentScanResult records for each page in the document.
              * Extract the output keys and values for each page and search for the required key.
              */ 
              private static String getValue(List<OcrDocumentScanResult> ocrDocumentScanResults, String key) {
                  String value = '';
                  for (OcrDocumentScanResult ocrScanResult : ocrDocumentScanResults) {
                      String response = ocrScanResult.ExtractedValues;
                      Map<String, Object> jsonMap = (Map<String, Object>) JSON.deserializeUntyped(response);
                      List<Object> keyValuePairList = (List<Object>) jsonMap.get(KEY_VALUE_PAIR);
                      List<Map<String, Object>> keyValuePairMapList = new List<Map<String, Object>>();
                      for (Object keyValuePair : keyValuePairList) {
                          Map<String, Object> keyValuePairMap = (Map<String, Object>) keyValuePair;
                          keyValuePairMapList.add(keyValuePairMap);
                      }        
                      for (Map<String, Object> keyValuePair : keyValuePairMapList) {
                          Map<String, Object> keyMap = (Map<String, Object>) keyValuePair.get('key');
                          if (keyMap.get(TEXT).equals(key)) {
                              Map<String, Object> valueMap = (Map<String, Object>) keyValuePair.get('value');
                              if(valueMap != null) {
                                  value = (String) valueMap.get(TEXT);
                                  break;
                              }
                          }
                      }
                  }
                  return value;
              }
          
              /**
              * This method creates a new record of objectType target object and saves values in one of 
              * the fields of the target object.
              * Since some target objects require mandatory fields for a record to be created,
              * we use requiredFields map that has keys as mandatory fields' API names
              * and values as per the usecase requirement.
              */
              private static void saveExtractedValuesInTargetObject(String key_extract, String value_extracted, String objectType, Map<String, String> requiredFields) {
                  SObject newRecord = (SObject) Type.forName(objectType).newInstance();
                  // Required field for record-creation
                  for (String key : requiredFields.keySet()) {
                      String val = requiredFields.get(key);
                      newRecord.put(key, val);
                  }
                  newRecord.put(key_extract, value_extracted);
                  insert newRecord;
              }
          }
           
          Загрузка
          Salesforce Help | Article