Cannot insert values into CDR's userfield with ODBC

I’m trying to insert call stats into the userfield column in my CDR’s. My logs show that the macro processes, but nothing shows up in the database. I see that for csv files the cdr.conf needs “userfield=yes”. Do I need to do the same thing for odbc somehow?

I tried this, but it didn’t work:

cdr.conf
[odbc]
loguserfield=yes

This is the macro I have in extensions_custom.conf:

[macro-hangupcall-custom]
; start of QoS reporting
exten => s,1,NoOp(Start QoS)
exten => s,n,NoOp(Packets Sent: ${CHANNEL(rtcp,txcount)})
exten => s,n,Set(CDR(userfield)=${CDR(userfield)} Packets Sent: ${CHANNEL(rtcp,txcount)})
exten => s,n(continue),NoOp(End of QoS)
exten => s,n,MacroExit()

The logs are showing this:

pbx.c: Executing [[email protected]:1] NoOp(“PJSIP/1001-00000002”, “Start QoS”) in new stack
pbx.c: Executing [[email protected]:2] NoOp(“PJSIP/1001-00000002”, “Packets Sent: 189”) in new stack
pbx.c: Executing [[email protected]:3] Set(“PJSIP/1001-00000002”, “CDR(userfield)= Packets Sent: 189”) in new stack
pbx.c: Executing [[email protected]:5] NoOp(“PJSIP/1001-00000002”, “End of QoS”) in new stack
pbx.c: Executing [[email protected]:6] MacroExit(“PJSIP/1001-00000002”, “”) in new stack
pbx.c: Executing [[email protected]:5] Hangup(“PJSIP/1001-00000002”, “”) in new stack

I just can’t seem to figure out if it is my cdr configuration or my dialplan that is causing this not to work. Thanks!!

I did a quick search and CDR Info Page might help.

I’m pretty sure either the SET() function is the wrong function to use, the structure of the Set() function isn’t right, or the second “CDR{userfield}” is getting in your way. I can’t really put my finger on it, but the command just doesn’t look right (too many right braces, for example?).

Thanks for the reply. I should add that I tried inserting plain text as well and it didn’t take.

exten => s,n,Set(CDR(userfield)=12345)

I was able to get it working by mapping an alias to the userfield. Below is the working configuration.

cdr_adaptive_odbc.conf

[asteriskcdrdb]
connection=asteriskcdrdb
table=cdr
alias start => calldate
alias qos => userfield

My macro:

[macro-hangupcall-custom]
; start of PJSIP QoS reporting
exten => s,1,NoOp(Start QoS)
exten => s,n,NoOp(Packets Sent: ${CHANNEL(rtcp,txcount)})
exten => s,n,Set(CDR(qos)=${CDR(qos)} Packets Sent: ${CHANNEL(rtcp,txcount)})
exten => s,n,Set(CDR(qos)=${CDR(qos)} Packets Received: ${CHANNEL(rtcp,rxcount)})
exten => s,n(continue),NoOp(End of QoS)
exten => s,n,MacroExit()