First step:
Let $X=\operatorname{Spec} A_1\cup \operatorname{Spec} A_2$ such that $\operatorname{Spec} A_1\cap \operatorname{Spec} A_2=\operatorname{Spec} A_{12}$.
Let $A_{12}=B[z_1,\dots, z_n]/(f_1,\dots, f_r)$.
Write $A_1=B[\lambda_1,\dots, \lambda_n]/(g_{11},\cdots, g_{1m})$ and $A_2=B[\mu_1,\dots, \mu_n]/(g_{21},\cdots, g_{2m}).$
Consider the map $A_1\to A_{12}$, and the images of $\lambda_i\mapsto p_i(\underline{z})$.
Similarly consider the map $A_2\to A_{12}$, and the images of $\mu_i\mapsto q_i(\underline{z})$.
Also consider $g_{1j}(p_1(\underline{z}),\dots, p_n(\underline{z}))=\sum_r c_rf_r$ in $B[z_1,\dots, z_n]$.
Similarly $g_{2j}(q_1(\underline{z}),\dots, q_n(\underline{z}))=\sum_r d_rf_r$ in $B[z_1,\dots, z_n]$
Let $C=\mathbb{Z}[\text{coef. of} ~f_i| i][\text{coef. of} ~g_{1i}| i][\text{coef. of} ~g_{2i}| i][\text{coef. of} ~p_i| i][\text{coef. of} ~q_i| i][\text{coef. of} ~c_r| r][\text{coef. of} ~d_r| r]$
Now write $R_1=C[\lambda_1,\dots, \lambda_n]/(g_{11},\cdots, g_{1m})$
and
$R_2=C[\mu_1,\dots, \mu_n]/(g_{21},\cdots, g_{2m})$ and $R_{12}= C[z_1,\dots, z_n]/(f_1,\dots, f_r)$.
We observe that the map $\operatorname{Spec} R_{12}\to \operatorname{Spec} R_1$ is an open immersion, similarly the map $\operatorname{Spec} R_{12}\to \operatorname{Spec} R_2$ is an open immersion.
We now glue $\operatorname{Spec} R_1$ and $\operatorname{Spec} R_2$ along $\operatorname{Spec} R_{12}$ to get $X'$.
So we have $X\to \operatorname{Spec} B$ as a pullback of a finitely presented map $X'\to \operatorname{Spec} C$.
$\operatorname{Spec}$to format $\operatorname{Spec}$ produces better spacing - I've upgraded your post with this change. – KReiser Aug 14 '21 at 06:50