Search code examples
jsonazure-logic-appsservicenowservicenow-rest-api

Service Now API in Logic Apps


I am trying to use the Logic Apps ServiceNow connector.

I have got most of the fields from the request, the last item which i need are the variables text inputs in ServiceNow. I have identified that i can get the information from sc_item_option_mtom table and sc_item_option respectively.

The output of sc_item_option_mtom looks like below -

     "result": [
                    {
                        "sys_id": "00d1ce4adb75c4144664a27314961454",
                        "sys_updated_by": "Bot.One",
                        "sys_created_on": "04/01/2020 12:23:21",
                        "sys_mod_count": "0",
                        "request_item": {
                            "display_value": "RITM0032344",
                            "link": "https://dev.service-now.com/api/now/v2/table/sc_req_item/ggd1ce4adb75c4144664a2731496195f"
                        },
                        "sc_item_option": {
                            "display_value": "ggd1ce4adb75c4144664a2731496195e",
                            "link": "https://dev.service-now.com/api/now/v2/table/sc_item_option/ggd1ce4adb75c4144664a2731496195e"
                        },
                        "sys_updated_on": "04/01/2020 12:23:21",
                        "sys_tags": "",
                        "sys_created_by": "Bot.One"
                    }
                  ]

I need to get sc_item_option.display_value to be used as a input into the sc_item_option table. When i do this in Logic apps, it create a for each loop(which is correct), but the option i get is a Dependent Item

Logic apps setup

When i run the logic app the Dependent Item looks like -

"sys_id={\"display_value\":\"ggd1ce4adb75c4144664a2731496195e\",\"link\":\"https://dev.service-now.com/api/now/v2/table/sc_item_option/ggd1ce4adb75c4144664a2731496195e"}"},

I've tried editing the code to just get the display_value. Things i have tried are -

  • sc_item_option.display_value.[0]
  • sc_item_option.display_value[0]
  • sc_item_option.[0]
  • sc_item_option[0]

Nothing seems to work and not give me the value which is in display_value.

Can someone help me and tell me what i am doing wrong ?

Full List Records file -

  "result": [
            {
                "sys_id": "00d1ce4adb75c4144664a27314961454",
                "sys_updated_by": "Bot.One",
                "sys_created_on": "04/01/2020 12:23:21",
                "sys_mod_count": "0",
                "request_item": {
                    "display_value": "RITM0032344",
                    "link": "https://yarratramsau.service-now.com/api/now/v2/table/sc_req_item/ggd1ce4adb75c4144664a2731496195f"
                },
                "sc_item_option": {
                    "display_value": "ccd1ce4adb75c4144664a2731496195e",
                    "link": "https://yarratramsau.service-now.com/api/now/v2/table/sc_item_option/ggd1ce4adb75c4144664a2731496195e"
                },
                "sys_updated_on": "04/01/2020 12:23:21",
                "sys_tags": "",
                "sys_created_by": "Bot.One"
            },
            {
                "sys_id": "0cd1ce4adb75c4144664a27314961960",
                "sys_updated_by": "Bot.One",
                "sys_created_on": "04/01/2020 12:23:21",
                "sys_mod_count": "0",
                "request_item": {
                    "display_value": "RITM0032344",
                    "link": "https://yarratramsau.service-now.com/api/now/v2/table/sc_req_item/ggd1ce4adb75c4144664a2731496195f"
                },
                "sc_item_option": {
                    "display_value": "4fd1ce4adb75c4144664a2731496195e",
                    "link": "https://yarratramsau.service-now.com/api/now/v2/table/sc_item_option/4fd1ce4adb75c4144664a2731496195e"
                },
                "sys_updated_on": "04/01/2020 12:23:21",
                "sys_tags": "",
                "sys_created_by": "Bot.One"
            },
            {
                "sys_id": "c0d1ce4adb75c4144664a27314961960",
                "sys_updated_by": "Bot.One",
                "sys_created_on": "04/01/2020 12:23:21",
                "sys_mod_count": "0",
                "request_item": {
                    "display_value": "RITM0032344",
                    "link": "https://yarratramsau.service-now.com/api/now/v2/table/sc_req_item/ggd1ce4adb75c4144664a2731496195f"
                },
                "sc_item_option": {
                    "display_value": "40a1ce4adb75c4144664a2731496195f",
                    "link": "https://yarratramsau.service-now.com/api/now/v2/table/sc_item_option/40a1ce4adb75c4144664a2731496195f"
                },
                "sys_updated_on": "04/01/2020 12:23:21",
                "sys_tags": "",
                "sys_created_by": "Bot.One"
            }
        ]


Solution

  • You can try to use this expression below to fill in the "Query" box of "List Records" action:

    body('Item_Options(sc_item_option_mtom)')[0].sc_item_option.display_value
    

    By the way, it seems there is just one item in the result of "sc_item_option_mtom", so you do not need to use the "For each" loop(I know it would create the "For each" automatically), but you just need to create the "List Records" action and input the expression above to the "Query" box of the action directly(without "For each" loop).

    Update:

    For the update of your requirements, you can refer to the solution below:

    Input the expression below to the "Query" box of "List Records" action:

    items('For_each').sc_item_option.display_value
    

    enter image description here

    So in the "Query" box of "List Records" action, it should be like:

    enter image description here