I'm writing CDR to mssql table with cdr_adaptive_odbc. This works fine in the sense that the record is written after the call.

But I'd like to write a cdr_record when the call comes in, before it is answered/aborted.

Reason: I'd like to add a function in our CRM-system: click this button and see the phonenumber of the incoming call, where the CDR-record is "ringing" or something. Then match the phonenumber with customer records, and show caller info on screen.

(I don't want to push the number to the CRM, it has to be a pull)

I have tried this:

exten => 13,1,noop()
same => n,forkcdr()
same => n,Wait(2)
same => n,dial(SIP/L13)
same => n,hangup()

but that does not create a new record in the database.

  • I don't want to push the number to the CRM, it has to be a pull what about pushing the number to a temporary table where it'll be pulled by the CRM later on ? Aug 27, 2015 at 1:20

2 Answers 2


Instead of using CDR, I log CEL to a table. Then I can see the call which are started (eventtype 1, CHANNEL_START), and see if the linkedid has corresponding events with eventtype 4 ANSWER and events with eventtype 2 CHANNEL_END

I then find the lastest customer-id with that phone number (a customer might register multiple time with the same number), and show the corresponding name.

I finally (just for kicks) show the talk-time and disposition from the CDR-record.

SELECT TOP 10 a.cid_num, 
          a.eventtime 'begin', 
          b.eventtime 'answer', 
          c.eventtime 'end', 
FROM   asteriskcel a 
   LEFT JOIN asteriskcel b 
          ON b.eventtype = 4 -- ANSWER
             AND b.linkedid = b.uniqueid 
             AND b.linkedid = a.linkedid 
   LEFT JOIN asteriskcel c 
          ON c.eventtype = 2 -- CHANNEL_END
             AND c.linkedid = c.uniqueid 
             AND c.linkedid = a.linkedid 
   LEFT JOIN (SELECT RIGHT(telefon, 8) tlf, 
                     Max(id)           maxid 
              FROM   t_kunder 
              GROUP  BY RIGHT(telefon, 8)) mk 
          ON RIGHT(a.cid_num, 8) = mk.tlf 
   LEFT JOIN t_kunder k 
          ON mk.maxid = k.id 
   LEFT JOIN bit_cdr cdr 
          ON cdr.linkedid = a.linkedid 
WHERE  a.eventtype = 1 -- CHANNEL_START
   AND a.linkedid = a.uniqueid 
   AND a.context = 'default' 
ORDER  BY a.eventtime DESC  

You can use forkCDR app to drop enother cdr at start

  • As stated in the original question, this did not work. It should have, that's why I tried in the first place.
    – Lenne
    Sep 7, 2015 at 5:20
  • It work if you use ResetCDR(vw)
    – arheops
    Sep 7, 2015 at 10:40

You must log in to answer this question.

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