Frank,
We just did the exact same thing that you are doing. Had the same problem. This is our second house to remodel, so have used the foam sealant before and it is absolutely ideal for situations just like yours. Only suggestion..allow the sealant to cure approx 24 hours before trimming off the excess. I know the instructions on the can say differently, but take it from someone who has used the product several times.
Good luck.
Terry A.