This is strictly up to the judge and the district attorney. Depending upon the charge, they may be willing to dismiss it to allow you to enlist. This will only be done if it is a very minor charge. You should ask your attorney, if you have one, to inquire. If you are unrepresented, as the assistant district attorney.