Synopsis:
CDR(<name>)Description:
CDR(<name>[|options])name may be one of the following:
- accountcode: The channel's account code.
- amaflags: DOCUMENTATION, BILL, IGNORE etc
- answer: Time the call was answered.
- billsec: Duration of the call once it was answered.
- channel: Channel name
- clid: Caller ID
- dcontext: Destination context
- disposition: ANSWERED, NO ANSWER, BUSY
- dst: Destination
- dstchannel: Destination channel
- duration: Duration of the call.
- end: Time the call ended.
- lastapp: Last app executed
- lastdata: Last app's arguments
- src: Source
- start: Time the call started.
- uniqueid: The channel's unique id.
- userfield: The channel's user specified field.
- any custom value that you wish to store.
options may be:
- r: Causes the function to search the entire stack of CDRs on the channel for the requested value.
- u: Retrieves the raw, unprocessed value.
All of the pre-defined CDR variables are read-only with the exception of the following:
- Asterisk 1.4
- accountcode
- amaflags
- userfield
- Asterisk 1.2
- accountcode
- userfield
Notes
- This function may be both read from and written to. However, most of the pre-defined values are read-only as described above.
- *CLI> core show function CDR
Return value
Returns the resulting string.Example
; Get the value of the duration CDR field and store it in a variableexten => s,1,Set(foo=${CDR(duration)})
; Update our accountcode field and then save some random music facts too
exten => s,1,Set(CDR(accountcode)=8675309)
exten => s,2,Set(CDR(MyFavoriteBand)=Foo Fighters)
exten => s,3,Set(CDR(MyFavoriteSong)=Hero)

Comments
333
;
; Example script to retrieve formatted and unformatted values using CDR
;
exten => s,1,Set(TIMEOUT(absolute)=15)
;
; ------------------------------------------
;
; This returns Caller ID Name & Number, eg. "John Doe" <3305551212>
;
exten => s,n,Set(v_clid=${CDR(clid)})
;
exten => s,n,NoOp(${v_clid})
;
; ------------------------------------------
;
; This returns Caller ID Number Only, eg. <3305551212>
;
exten => s,n,Set(v_src=${CDR(src)})
;
exten => s,n,NoOp(${v_src})
;
; ------------------------------------------
;
; Call start time in different formats
;
exten => s,n,Set(v_start=${CDR(start)})
exten => s,n,Set(r_start=${CDR(start|r)})
exten => s,n,Set(u_start=${CDR(start|u)})
;
exten => s,n,NoOp(${v_start})
exten => s,n,NoOp(${r_start})
exten => s,n,NoOp(${u_start})
;
; ------------------------------------------
;
; Status of call, eg BUSY, ANSWERED
;
exten => s,n,Set(v_disposition=${CDR(disposition)})
exten => s,n,Set(r_disposition=${CDR(disposition|r)})
exten => s,n,Set(u_disposition=${CDR(disposition|u)})
;
exten => s,n,NoOp(${v_disposition})
exten => s,n,NoOp(${r_disposition})
exten => s,n,NoOp(${u_disposition})
;
; ------------------------------------------
;
exten => s,n,Hangup()
;
; Call timeout, broken connection, say goodbye and hangup
;
;
exten => T,1,Playback(im-sorry)
exten => T,n,Playback(vm-goodbye)
exten => T,n,Hangup()
;
; -----------------------------------------------------------------------
3333 examples using CDR()
; -------- (examples from use in asterisk version 1.4.7) -------------
;
; Initialize two vars
;
exten => s,1,Set(Var_1=foo)
exten => s,n,Set(Var_2=bar)
;
; Remember "userfield" is not a token that you can replace with an identifier of your choice
; it is a constant.
;
exten => s,n,Set(CDR(userfield)=bling blong blang)
;
; Stores "bling blong blang" in untagged field at the end of the CDR in
; /var/log/asterisk/cdr-csv/Master.csv
; Not a very useful form
;
exten => s,n,Set(CDR(userfield)=${Var_1}_${Var_2})
;
; Stores "foo_bar" in the same field at the end of the CDR
;
exten => s,n,Set(CDR(userfield)=At ${CDR(start)} From callerID ${CDR(clid)} eat your ${CDR()} )
;
- At 2007-07-12 22
- 56:44 From callerID guest eat your foo_bar
;; ---------------------------------------------
333All fields except userfield and account code are read only!
These fields are read-only.
Also (mr picky!), "astapp" above of course should be 'lastapp'.