We have developed an approach to determine the magnetoelastic coupling constant of magnetic layers in thin film heterostructures. The film is formed on a piezoelectric substrate between two interdigital transducers (IDTs), a platform often used to construct a surface acoustic wave device. With the substrate piezoelectricity, strain is induced into the film by applying a dc voltage to the IDTs. The strain causes changes in the magnetization direction of the magnetic layer, which is probed by measuring changes, if any, in the transverse resistance of the heterostructure. We find that the extracted magnetoelastic coupling constant of the magnetic layer (CoFeB) depends on the film stacking. Such change can be accounted for provided that the elastic properties of the layers that constitute the heterostructures are taken into account. The on-chip all-electrical approach described here provides a versatile means to quantitatively assess the magnetoelastic coupling constant of thin film heterostructures.