Use a computed solution as boundary value

Dear all,
I am new on FreeFem. I want to compute some shape derivatives and therefore I need to Solve first a PDE with a prescribed boundary data and then I need to capture a partial derivative of the computed solution to take it as new data on the boundary.
I naively tried this (u1,u2) being the computed solution :
Xh U1 = dx(u1)(x,y);
Xh U2 = dx(u2)(x,y);
and then
on(body,u1=U1([x,y]),u2=U2([x,y]))
but this does not work.
Then this :
Up1([x, y]) = U1(x,y);
Up2([x, y]) = U2(x,y);
and then
on(body,u1=Up1([x,y]),u2=Up2([x,y]))
This doesn’t work neither.
I can indeed evaluate U1 and U2 at any given point of the boundary so I have tried to rebuild the new boundary data from an interpolation but I was not successful.
Does someone know how to solve this ? I have checked the documentation and the forum but I do not find any example I can mirror.
Thanks in advance and best,
Denis.

Theoretical this works:
but try :
on(body,u1=U1,u2=U2)

I restarted from scratch and it works just as I was trying or as you suggest. Probably some other thing was wrong in my code. Thanks for your quick answer !