function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kriti vkriti v 

How can we call apex controller method on call back of omni channel toolkit API like getagentworks etc

We are calling getagentworks function, on call back of this i need to call apex controller method. But, getagentworks is asynchronous and returns a promise, before completion of getagentworks it is calling apex controller. How to resolve promise 
Raj VakatiRaj Vakati
Sample code is here 
<aura:component implements="flexipage:availableForAllPageTypes" access="global"  controller="hellocon">
    <lightning:omniToolkitAPI aura:id="omniToolkit" />
    <lightning:button label="Get Agent works" onclick="{! c.getAgentWorks }" /> 
</aura:component>
 
({
    getAgentWorks: function(cmp, evt, hlp) {
        var omniAPI = cmp.find("omniToolkit");
        omniAPI.getAgentWorks().then(function(result) {
            var works = JSON.parse(result.works);
           
		   var actoin = cmp.get("c.ex");
		   ... do other work here 
		   
        }).catch(function(error) {
            console.log(error);
        });
    }
})
 
public class hellocon{
	@AuraEnabled 
	public static String ex(){
		
		
	}
	
}

 
kriti vkriti v
Thanks for reply. I tried this, before completing the execution of agentworks it is calling backend method first.