Skip to main content
Community site session details

Community site session details

Session Id : EHXQkVSEqcRTp6JzmNn2gw
Power Pages - Design & Build
Unanswered

how to call web api synchronously in power portals

Like (0) ShareShare
ReportReport
Posted on 22 May 2024 14:09:08 by 13

I am executing the two javascript function 

 

1) function ===>  calling web api and reading the values

 

------if first function return the value  then no need to call the second function

2) second function===> dynamically creating the table 

 

but every time it's calling the second function because first function is working as asynchronous and giving me output after second function execution .

Categories:
  • Fubar Profile Picture
    8,056 Super User 2025 Season 2 on 23 May 2024 at 22:40:22
    Re: how to call web api synchronously in power portals

    As I said, nest them

    function functionxyz(){
     // do stuff, do another safe ajax etc etc
    }
    
    function functionabc(){
    
    var exists = false;
    var variable = some value;
    webapi.safeAjax({
     type: "GET",
     url: "api url",
     contentType: "application/json",
     success :function (res){
     res.value.forEach(function(record){
     
     if(record.column==variable ){
     exists=true;
     console.log("Match");
     }else{
     exists=false;
     console.log("Non Match");
     }
     })
     if(exists == true){
     functionxyz();
     }
     }
    }
    
    functionabc();

     

    Could also chain webapi.safeAjax(............).then(//next call here etc)

     

  • sumitLTIM Profile Picture
    13 on 23 May 2024 at 05:45:51
    Re: how to call web api synchronously in power portals
    1) first function
    var exists = false;
    var variable = some value;
    webapi.safeAjax({
        type: "GET",
        url: "api url",
        contentType: "application/json",
        success :function (res){
            res.value.forEach(function(record){
               
                if(record.column==variable ){
                  exists=true;
                  console.log("Match");
                }else{
                  exists=false;
                  console.log("Non Match");
                }
              })
        }
     
    if exists return true then I need to call another function which is calling web api again for different table
    2) function truewebapi ()
     
    if exists return false then I need to call another function which is calling web api again for different table
    3) function falsewebapi ()
     
    again on the basis of  truewebapi() and falsewebapi() function I need to call another function which again calling some web api,But everytime it's giving me false value from first step because of asynchronous call.
  • Fubar Profile Picture
    8,056 Super User 2025 Season 2 on 22 May 2024 at 21:46:03
    Re: how to call web api synchronously in power portals

    Chain them together or nest them - depending on what you are doing use .then() or call the second one from inside the results of the first one.

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

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#2
Lucas001 Profile Picture

Lucas001 48 Super User 2025 Season 2

#3
KevinGador Profile Picture

KevinGador 44 Super User 2025 Season 2

Featured topics

Loading complete