Setting variable before answer ARI

ari.on(‘ChannelStateChange’, async function (event, outgoingChannel) {
const eventName = “ChannelStateChange”;
const { state } = event.channel;
if (state == “Ringing”) {
const currentTime = moment().format(‘YYYY-MM-DD-ddd h:mm:ss’);
const payload = { variable: “CDR(ring_time)”, value: currentTime }
await outgoingChannel.setChannelVar(payload).catch(err => log(“Error : unable to store ringing state on channel :”, outgoingChannel.id, err.message));
}
});

I’m facing an issue while setting CDR(“ring_time”) before answers
it throwing me an error “Channel is not in stasis application”.
Kindly help thanks.

As the message says, until the channel is in ARI you can’t do that operation. You’d have to store it yourself somewhere and set it on the channel afterwards.