Originally Posted by zeshanlahoria
[...] do i have to recover in stock rom, unlock the phone using the code and than install the custom rom again?
Yes, that is what you will need to do. As you can only enter an unlock code on a stock ROM (or one of the numerous custom ROM based on the stock one), you won't be able to make it work on CyanogenMod or any AOSP derivatives. You will have to revert back to stock, then (if you want to try a cutom ROM) install another custom ROM of your choice, be it CM or anything else.
Though if you currently have CM installed in your device, you most certainly already have a custom recovery (TWRP, CWM, PhilZ Touch...), which make it even easier for you to flash ROMs at your will -- the step of installing a custom recovery is already done. So browse the AT&T SIII Android Development forum
, choose a stock-based ROM, install it -- pay close attention to the installation instructions in the ROM's thread --, unlock your phone; then repeat those steps to install another ROM if you want to.