Step 5: Use a rule to extract the vendor number

The data returned by SAP is a very long data string, so in this step we'll create a rule to extract only the information we need -- in this case, the vendor number -- from the SAP data.

  1. In InfoPath, create a Text field called Vendor Number.

  2. Now we'll create a new rule. In the form/canvas area of InfoPath, right-click the Log field, click Rules, and then Manage Rules.

  3. Name the rule Vendor Number Extract. Click Add, and then click Set a field's value.

  4. Click Insert Function, and then click Substring.

    We're using this substring statement because the Vendor Number begins at the 8th character in the string returned by SAP, and the number is 10 characters long.

    After the function is inserted, click OK.

    (See the screenshot below for the exact function.)

  5. The summary is displayed, as shown below.

  6. Click OK.

Creating a conditional rule

Now we'll create some rules in case an error is generated.

Learn more about adding rules in InfoPath

This first rule will set the Vendor Number value to 'blank' (empty space) if the log field begins with 'Err'.

  1. Right-click the Log field, and then click Create Rule.

  2. Click Add.
  3. Under Condition, click None-Rule runs when field changes to create a new condition.
  4. Create an IF condition so that if the log field starts with Err (this is case sensitive), then set the Vendor Number to an empty space.
  5. Click OK.

The second rule will apply formatting to the field to visually indicate to the user that an error has occurred.

  1. Right-click the Log field, and then click Create Rule.
  2. Click New, and then click Formatting.

  3. Click Add.
  4. Under Condition, click None-Rule runs when field changes to create a new condition.
  5. Create a condition so that if the log field does not begin with "Success", then the field will be highlighted in yellow. See the example below.

  6. Click OK.

In this step we have:

  • Created a field for Vendor Number, which is populated by an SAP data connection.
  • Applied rules to extract only the vendor number from the data returned by SAP.
  • Applied rules in case of an error.