Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix foreach issue and update some schema examples #3704

Merged
merged 3 commits into from
Apr 14, 2020
Merged

Conversation

luhan2017
Copy link
Contributor

Fixes #3680 and #3700

@luhan2017
Copy link
Contributor Author

luhan2017 commented Apr 9, 2020

@vishwacsena, I did want to add ForeachPage, but I found that the Nested ForeachPage is not working as expected. Here is a test case I created:

@@ -0,0 +1,138 @@
{
    "$schema": "../../../../schemas/sdk.schema",
  "$kind": "Microsoft.Test.Script",
  "dialog": {
    "$kind": "Microsoft.AdaptiveDialog",
    "id": "root",
    "triggers": [
      {
        "$kind": "Microsoft.OnBeginDialog",
        "actions": [
          {
            "$kind": "Microsoft.SetProperty",
            "property": "dialog.todo",
            "value": "=[]"
          },
          {
            "$kind": "Microsoft.EditArray",
            "itemsProperty": "dialog.todo",
            "changeType": "push",
            "value": "=1"
          },
          {
            "$kind": "Microsoft.EditArray",
            "itemsProperty": "dialog.todo",
            "changeType": "push",
            "value": "=2"
          },
          {
            "$kind": "Microsoft.EditArray",
            "itemsProperty": "dialog.todo",
            "changeType": "push",
            "value": "=3"
          },
          {
            "$kind": "Microsoft.EditArray",
            "itemsProperty": "dialog.todo",
            "changeType": "push",
            "value": "=4"
          },
          {
            "$kind": "Microsoft.EditArray",
            "itemsProperty": "dialog.todo",
            "changeType": "push",
            "value": "=5"
          },
          {
            "$kind": "Microsoft.EditArray",
            "itemsProperty": "dialog.todo",
            "changeType": "push",
            "value": "=6"
          },
          {
            "$kind": "Microsoft.ForeachPage",
            "itemsProperty": "dialog.todo",
            "pageSize": 4,
            "pageIndex": "dialog.foreachpage.outerIndex",
            "pageValue": "dialog.foreachpage.outerValue",
            "actions": [
              {
                "$kind": "Microsoft.ForeachPage",
                "itemsProperty": "dialog.foreachpage.outerValue",
                "pageSize": 2,
                "actions": [
                  {
                    "$kind": "Microsoft.SendActivity",
                    "activity": "This page have ${count(dialog.foreach.page)} items"
                  },
                  {
                    "$kind": "Microsoft.Foreach",
                    "itemsProperty": "dialog.foreach.page",
                    "actions": [
                      {
                        "$kind": "Microsoft.SendActivity",
                        "activity": "index is: ${dialog.foreach.index} and value is: ${dialog.foreach.value}"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
              "$kind":"Microsoft.SendActivity",
              "activity":"done"
          }
        ]
      }
    ],
    "autoEndDialog": true,
    "defaultResultProperty": "dialog.result"
  },
  "script": [
    {
      "$kind": "Microsoft.Test.UserSays",
      "text": "hi"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "This page have 2 items"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 0 and value is: 1"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 1 and value is: 2"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "This page have 2 items"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 0 and value is: 3"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 1 and value is: 4"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "This page have 2 items"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 0 and value is: 5"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 1 and value is: 6"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "done"
    }
  ]
}

But in fact, it didn't run the second iteration of the outer ForeachPage. the actually result missed the three steps.

    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "This page have 2 items"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 0 and value is: 5"
    },
    {
      "$kind": "Microsoft.Test.AssertReply",
      "text": "index is: 1 and value is: 6"
    },

@tomlm and @Stevenic any idea why this happening?

Copy link
Contributor

@tomlm tomlm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@vishwacsena
Copy link
Contributor

@luhan2017 were you able to get past the issues with ForEachPage?

@luhan2017
Copy link
Contributor Author

@vishwacsena , I have figured out why the foreachPage nested not working. it can be resolved by resetting the PageIndex in the BeginDialog. I've update the ForeachPage with schema and test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

foreach nesting error
3 participants