web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Call external URL fetch data

(0) ShareShare
ReportReport
Posted on by 2

Hi Experts,

I am writing JavaScript to fetch data from a logic app endpoint. The code like below:

 

function DynamicFlyoutMenu(commandProperties) {

    debugger;
    var templates = []; //global templates variable

    const requestOptions = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ get_templates: 'Yes' })
    };

    fetch('prod-16.canadaeast.logic.azure.com:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'requestOptions)
        .then(response => response.json())
        .then(data => {

            alert(JSON.stringify(data));
            for (const key in data) {
                console.log(`${JSON.stringify(data[key])}`//access values

                for (var i in data)
                    templates.push([data[i]]);
                templates = templates[0][0];
            }
        })

==========================================================
I need to get the template array, but when I run the script, the templates still empty, but the alert display the data like below

{"all-template-data":
[
{"templateName":"Temp001.docx","templateId":"DOC001"},
{"templateName":"Temp002.docx","templateId":"DOC002"},
{"templateName":"Temp003.docx","templateId":"DOC003"}
]
}
Can you help to suggest correct code? Thanks.
I have the same question (0)
  • Suggested answer
    Steve Zhao2 Profile Picture
    Microsoft Employee on at

    Hi ALL365,

    Your code is correct. You say that the templates still empty. S0, where do you console the templates, inside the then() or outside?

    if you console the templates array inside the then() like this:

    function DynamicFlyoutMenu(commandProperties) {
        debugger;
        var templates = []; //global templates variable
        const requestOptions = {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ get_templates: 'Yes' })
        };
        fetch('prod-16.canadaeast.logic.azure.com:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'requestOptions)
            .then(response => response.json())
            .then(data => {
                alert(JSON.stringify(data));
                for (const key in data) {
                    console.log(`${JSON.stringify(data[key])}`//access values
                    for (var i in data)
                        templates.push([data[i]]);
                    templates = templates[0][0];
                }
                console.log(templates);
            })
    }
    It should work fine.
    If outside, it could cause synchronization issues. You need to use async/await to resolve this.
  • ALAN365 Profile Picture
    2 on at

    Thank you Steve.

    As per your suggestion, I added console.log(templates); in then() and run the code, here is debug result:

    docgen.JPG

    templates array is still empty. How to fix it? Thanks

  • ALAN365 Profile Picture
    2 on at

    Hi,

    Have an idea, please.

  • ALAN365 Profile Picture
    2 on at

    I have wrapped up the code in a HTML file to test, the code like below:

    <html>

    <head>

       <meta content="text/html; charset = ISO-8859-1" http-equiv="content-type">

       <script src="ajax.googleapis.com/.../script>

       <script type="application/javascript">

           function loadJSON() {

               debugger;

               var url = "prod-xx.canadaeast.logic.azure.com:xxxxxxxxxxxxxxxxxxxxxxxxxx;

               // var params = {

               //     "get_templates": "Yes"

               // }

               var templates = []; //global templates variable

               const requestOptions = {

                   method: 'POST',

                   headers: {

                       'Content-Type': 'application/json'

                   },

                   body: JSON.stringify({

                       get_templates: 'Yes'

                   })

               };

               fetch(url, requestOptions)

                   .then(response => response.json())

                   .then(data => {

                       alert(JSON.stringify(data));

                       for (var i in data)

                           templates.push([data[i]]);

                       templates = templates[0][0];

                       console.log(templates);

                   })

           }

       </script>

       <title>Document Generation</title>

    </head>

    <body>

       <h1>Template Info</h1>

       <div class="central">

           <button type="button" onclick="loadJSON()">Show Info </button>

       </div>

       <div id="templateName"></div>

       <div id="templateId"></div>

    </body>

    </html>

    Cannot get templates value. Please give me advice. Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 93

#2
Subra Profile Picture

Subra 90

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 72 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans