Skip to content

Flow Development Assignments - Solutions

Solution 1 - Return Notification Number in Result

Section titled “Solution 1 - Return Notification Number in Result”
  1. We need to add a JSON Parser step to extract the Notification Number from the BAPI Save Notif step
  2. Now select the BAPI Save Notif node and click on + and select JSON Parser to add the JSON parser node.
  3. The JSON Parser node is now opened and you can configure it.
    1. Change the title to Prepare Result and remember to connect the BAPI Save Notif node Success connector to this node (else the expression builder will not display all the possible fields and nodes)
    2. Since we want to work with the previous step results, click on the Previous Step section
    3. For Map Field Name select BAPI Save Notif Result
    4. Under Expression click on the :fontawesome-solid-wrench: icon to open the Expression Builder
    5. If not already copied, close the dialog and click on arrow icon next to Run Flow. From Run History select the last run. Expand the BAPI Save Notif step and copy the result
    6. The output from this step is as below:
      {
      "NOTIFHEADER": {
      "MARKER_DISTANCE_UNIT_ISO": "",
      "MARKER_DISTANCE_UNIT": "",
      "MARKER_DISTANCE_END_POINT": "",
      "MARKER_END_POINT": "",
      "MARKER_DISTANCE_START_POINT": "",
      "MARKER_START_POINT": "",
      "STAT_PROF": "",
      "USERSTATUS": "",
      "USER_ST": "",
      "SYS_STATUS": "",
      "SECOND_OFFSET_UNIT_ISO": "",
      "SECOND_OFFSET_UNIT": "",
      "SECOND_OFFSET_VALUE": "",
      "SECOND_OFFSET_TYPE_CODE": "",
      "FIRST_OFFSET_UNIT_ISO": "",
      "FIRST_OFFSET_UNIT": "",
      "FIRST_OFFSET_VALUE": "",
      "FIRST_OFFSET_TYPE_CODE": "",
      "LINEAR_UNIT_ISO": "",
      "LINEAR_UNIT": "",
      "LINEAR_LENGTH": "",
      "END_POINT": "",
      "START_POINT": "",
      "MATERIAL_VERSION": "",
      "MATERIAL_GUID": "",
      "MATERIAL_EXTERNAL": "",
      "ASSEMBLY_VERSION": "",
      "ASSEMBLY_GUID": "",
      "ASSEMBLY_EXTERNAL": "",
      "SCENARIO": "",
      "ITM_NUMBER": "000000",
      "DOC_NUMBER": "",
      "ADDR_NO_LOC_ACC": "",
      "DIST_CHAN_LOC_ACC": "",
      "DIVISION_LOC_ACC": "",
      "SALES_ORG_LOC_ACC": "",
      "COMP_CODE": "GB01",
      "STLMTORDER": "",
      "STDGORD": "",
      "SUB_NUMBER": "",
      "ASSET_NO": "",
      "WBS_ELEMENT": "",
      "COSTCENTER": "MAINT",
      "CO_AREA": "GB01",
      "BUS_AREA": "",
      "PP_WKCTR": "10000001",
      "PLSECTN": "",
      "MAINTROOM": "",
      "MAINTLOC": "ALBN",
      "MAINTPLANT": "KALB",
      "SORTFIELD": "",
      "ABCINDIC": "",
      "FUNCT_LOC": "A-ALBN-46- Z-4601",
      "NOTIFTMEZ": "INDIA",
      "SALES_GRP": "",
      "SALES_OFFICE": "",
      "DEVICEDATA": "",
      "DELETE_FLAG": "",
      "SERIALNO": "",
      "PM_WKCTR": "10000001",
      "CODING": "",
      "CODE_GROUP": "",
      "CAT_TYPE": "D",
      "CREATED_AT": "09:37:39",
      "CHANGED_AT": "00:00:00",
      "ADDR_NUMBER": "",
      "DISTR_CHAN": "",
      "SALES_ORG": "",
      "DIVISION": "",
      "PURCH_NO_C": "",
      "SALES_ORD": "",
      "REFTIME": "09:37:39",
      "REFDATE": "2024-03-22",
      "PRILANG": "E",
      "LONG_TEXT": "",
      "CATPROFILE": "000000001",
      "COMPTIME": "00:00:00",
      "OBJECT_NO": "QM000010001106",
      "CUST_NO": "",
      "MATERIAL": "",
      "ORDERID": "",
      "DESENDTM": "00:00:00",
      "DESSTTIME": "09:37:38",
      "DESSTDATE": "2024-03-22",
      "REPORTEDBY": "",
      "NOTIF_DATE": "2024-03-22",
      "NOTIFTIME": "09:37:38",
      "CHANGED_BY": "",
      "CREATED_ON": "2024-03-22",
      "CREATED_BY": "INDUSER",
      "PRIORITY": "",
      "PRIOTYPE": "PM",
      "SHORT_TEXT": "Short Text ????????",
      "NOTIF_TYPE": "M1",
      "MAINTITEM": "",
      "MNTCALL_NO": 0,
      "MNTPLAN": "",
      "PLANGROUP": "46",
      "ISOCODE_UNIT": "",
      "UNIT": "H",
      "DOWNTIME": 0,
      "ENDMLFNTIME": "00:00:00",
      "STRMLFNTIME": "00:00:00",
      "BREAKDOWN": "",
      "ASSEMBLY": "",
      "EQUIPMENT": "AN-JC-4601",
      "LOC_ACC": "000000002262",
      "PLANPLANT": "KALB",
      "NOTIF_NO": "000010001106"
      }
      }
    7. We now need to extract the NOTIF_NO and prepare the result. Lets use the below expression:
      $.NOTIFHEADER.NOTIF_NO
    8. Paste the expression from the step above into the Mapping Expression window on the right. The extracted data is now displayed at the bottom. Confirm that what is displayed is correct.
    9. Now Click on Save and close the builder,
    10. Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
  4. Select the Prepare Result node and click on + and search for response and select the Response node.
  5. The Response node is now opened and you can configure it.
    1. Change the title to Send Notif Result and remember to connect the Prepare Result node Success connector above to this node (else the expression builder will not display all the possible fields and nodes)
    2. Select the Success option
    3. Set the HTTP Code to 200 to signify HTTP Success
    4. For Body click on the :fontawesome-solid-wrench: icon to open the Expression Builder
    5. Type in Notification created:. Place the cursor after the message and then Select Result below the Prepare Result entry
    6. Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
  6. Now click on Publish button to save and compile the flow. If the compilation is successful it will also be published and we can run it to test.
  7. Run the flow to test it and check the result.
  1. Copy the Post Message To Teams flow to Post Message To Teams v2 using the Copy Flow option in the Forms list
  2. Change the Flow Input to the format expected by Teams (use attribute name as text instead of message)
  3. Delete the JSON Parser node and connect the Sub Flow node directly to the Send Teams Message node
  4. Set the Flow Input as body parameter directly in the Send Teams Message node. Run and check if the message is received
  5. Finally, change the Save to Database Flow to use the Post Message To Teams v2 and change the Flow Input as above. Run the flow and check if the new message is received

Solution 3 - OpenAI Integration for Teams Chatbot

Section titled “Solution 3 - OpenAI Integration for Teams Chatbot”
  1. Login to OpenAI developer portal and obtain an API Key
  2. Click on the More button in the Computer Inspection row and choose the Environment option
  3. In the Environment dialog, click on the Add button
  4. Set the key to OPENAI_API_KEY and the value to the API key that you obtained from the OpenAI portal
  1. Click on the More option to open the Flows and the Teams Chatbot flow again.
  2. Click on the Extract Equipment node and click on the :fontawesome-solid-circle-plus: icon that is displayed below the node
  3. Search for the Http node by typing in http and clicking on it
  4. The HTTP node is now opened and you can configure it.
    1. Change the title to Process OpenAI and remember to connect the Webhook Flow node Success connector to this node (else the expression builder will not display all the possible fields and nodes)
    2. We will be adding a new system to communicate with the OpenAI Server. Later if we need to work with a different API provided by the OpenAI server we can reuse the server and modify the URL path we are communicating to. Click on :fontawesome-solid-plus: icon next to the Server dropdown.
    3. You will need to refer to the OpenAI developer documentation
    4. The Add System dialog is displayed. Enter the following data:
      • Description: OpenAI (or anything else you desire)
      • Identifier: This is a unique identifier for the system, enter open-ai
      • URL: Set it to https://api.openai.com
      • Set the Authentication Type to None, we will configure the API token in the http call itself
      • Set the OAuth Provider to None
      • Save the system
    5. Now choose the newly added open-ai system (or the name that you entered above)
    6. Change the HTTP Action to Post
    7. Content-Type and Accept needs to be applicaiton/json
    8. For URL Path set it to /v1/chat/completions
    9. Lets configure the authentication now. We didn’t use any standard authentication type at system level since a static token only has to be posted. Click on + icon to add a key value pair
      • Enter Authorization for the Key.
      • For Value click on the :fontawesome-solid-wrench: icon to open the Expression Builder
      • For expression, first type in ***Bearer *** and then from the list under Environment choose OPENAI_API_KEY
    10. Now we need to configure the message. The OpenAI API expects the message in JSON format in the Body parameter. Scroll down to the Body Data configuration and click on the :fontawesome-solid-wrench: icon to display the expression builder.
    11. Paste the below JSON into the Expression field.
      {
      "model": "gpt-3.5-turbo",
      "messages": [
      {
      "role": "system",
      "content": "You are an assistant who can extract computer equipment or part names from the content. For e.g for the message <<<Find inventory for memory>>> return the equipment <<<memory>>> as the result. Return the extracted word only and nothing else. If you do not find any equipment return the text <<<notfound>>>. Do not guess any equipment names."
      },
      {
      "role": "user",
      "content": ""
      }
      ]
      }
    12. Now carefully place the cursor after the first double quote after the : sign in the text “content”: ""
    13. Now from the list after Extract Equipment select Result so that the text looks like this now: “content”: “${extractequipment_result}”
    14. Finally set the parameter Success HTTP Code to 200 so that any other code returned by OpenAI is treated as an error
  5. We now need to extract the OpenAI response. Click on the Process OpenAI node and click on the :fontawesome-solid-circle-plus: icon that is displayed below the node
  6. Search for the JSON Parser node by typing in json and clicking on it
  7. The JSON Parser node is now opened and you can configure it.
    1. Change the title to Extract OpenAI and remember to connect the Process OpenAI node Success connector above to this node (else the expression builder will not display all the possible fields and nodes)
    2. Since we want to work with the returned message, click on the Previous Steps section
    3. For Map Field Name select Process OpenAI and then Result
    4. We need the message format returned by the Process OpenAI master data method. For the response format check OpenAI developer documentation Remember the returned data will be embedded in another JSON as below:
      {
      "httpCode": 200,
      "headers": {},
      "data": {
      "model": "gpt-3.5-turbo-0125",
      "choices": [
      {
      "index": 0,
      "message": {
      "role": "assistant",
      "content": "computer"
      },
      "finish_reason": "stop"
      }
      ],
      "usage": {}
      }
      }
    5. Under Expression click on the :fontawesome-solid-wrench: icon to open the Expression Builder
    6. Copy and paste the JSON above into the JSON window on the left
    7. The expression builder we use for JSON parsing is a tool called Jsonata
    8. We need to extract the inventory now. However remember that if the equipment was not found an empty array will be returned. So we use the {'$'}exists*() function to make sure that the attribute exists. Also we will be using data[0] as we want the first returned row.
      {'$'}.data.choices[0].message.content
    9. Paste the expression from the step above into the Mapping Expression window on the right. The extracted equipment computer is now displayed at the bottom. Confirm that what is displayed is correct.
    10. Now Click on Save and close the builder,
    11. Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
  8. Connect the Extract OpenAI node to Read Inventory
  9. Open the Read Inventory node and under Filter open the expression builder by clicking on the :fontawesome-solid-wrench: icon
  10. In the condition change the value being compared to the Result of the step Extract OpenAI so that the equipment identified by OpenAI can be used to run the master data query
  11. Additionally select the OR option and add another field by clicking on + icon. Choose the Equipment Name field and set toggle to Custom and the value again to the Result from the step Process OpenAI so that we can check for name or id
  12. Now click on Publish button to save and compile the chatbot flow. If the compilation is successful it will also be published and we can now test it.
  13. Login to Teams and as before send a more detailed query and if all works well and OpenAI identifies the equipment you should get back the answer.
  14. Congratulations, you have now successfully built your first GenAI Turbo Apps Chatbot for MS Teams