Well it looks like nothing has change since 2012 in this subject, so i'm wondering what's wrong?
Just tested Vamitul's code in answer #25 with InDesign CC 2018.1 on Windows 10. It is doing exactly what it should. RGB images in JPEG format with 300 ppi effective resolution. If you want CMYK you have to change line 15.
prfs.jpegColorSpace = JpegColorSpaceEnum.RGB;
prfs.jpegColorSpace = JpegColorSpaceEnum.CMYK;
I also tested this. No problem on my side…
So again. Post your code. Maybe something's went wrong by copy/paste it ?
i saw CMYK where RGB was written
but still in script resolution is set to 300dpi and my result is 72
here are my files (i made 2 versions: 1 for rgb & 1 for cmyk)