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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / how to call web api sy...
Power Pages
Unanswered

how to call web api synchronously in power portals

(0) ShareShare
ReportReport
Posted on 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:
I have the same question (0)
  • Fubar Profile Picture
    8,346 Super User 2025 Season 2 on at

    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.

  • sumitLTIM Profile Picture
    13 on at
    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,346 Super User 2025 Season 2 on at

    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)

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 70 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard