0

Uncaught Error in $A.getCallback() [Cannot read property 'setServicePresenceStatus' of undefined]

This error is related to Omni Channel Presence status availability. Error is occurring only some times but not all the times.

Could you please check and let me know the issue.

Below is the piece of code

        window.setTimeout(
            $A.getCallback(function() {
                var omniAPI = component.find("omniToolkit");
                omniAPI.setServicePresenceStatus({
                    statusId: $A.get('$Label.c.CGA_OmniChannel_StatusId'),
                    callback: function(result) {
                        if (result.success) {
                            console.log('Set status successful');
                            console.log(result.statusApiName);
                        } else {
                            console.log('Set status failed');
                        }
                    }
                });
            }), 10000
        )

1 Answer 1

0

When you use setTimeout the context of the Aura framework sometimes gets lost, even though you have used $A.getCallback.

I suggest moving var omniAPI = component.find("omniToolkit"); outside the setTimeout and then just use its reference inside $A.getCallback.

Something like this:

var omniAPI = component.find("omniToolkit");
window.setTimeout(
    $A.getCallback(function() {
        omniAPI.setServicePresenceStatus({
            statusId: $A.get('$Label.c.CGA_OmniChannel_StatusId'),
            callback: function(result) {
                if (result.success) {
                    console.log('Set status successful');
                    console.log(result.statusApiName);
                } else {
                    console.log('Set status failed');
                }
            }
        });
    }), 10000
)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .