How can I get the maximum of an absolute value of an objective

Many thanks! But I tried this and get status is INFEASIBLE.

If l equals -2, then 0<= neg <=-2? This seems not to be straightforward to me. Also, in the link

https://docs.mosek.com/modeling-cookbook/mio.html#exact-absolute-value

you posted, there seems should be

@constraint(model, pos <= M * z)
@constraint(model, neg <= M * (1 - z))

and the constant M is an a priori known upper bound on |x|, which should be positive.

And indeed in my case the objective to be optimized is of type AffExpr, so I added a line

@constraint(model, x == x_AffExpr)

where x_AffExpr is a known expression.

It would be great if you can explain a little bit more. Thanks!