Código
assign p.id
, t.tipo_pedido
from pedidos p
join tipos_pedidos t on t.id = p.tipo_pedido_id
where p.id = ${ctx.event.object.id};
if '${tipo_pedido}' not in ('ORCAMENTO') then
return 'ok';
end-if;
assign id as tipo_pedido_requisicao_id
from tipos_pedidos 
where tipo_pedido = 'REQUISICAO';
   
assign id as tipo_pedido_requisicao_id
from tipos_pedidos 
where tipo_pedido = 'REQUISICAO';
for rec in
   select ped.estabelecimento_id
   , ped.cliente_id
   , ped.fornecedor_id
   , iped.produto_id
   , iped.id as item_pedido_id
   from itens_pedidos iped
   join pedidos ped on ped.id = iped.pedido_id
   where ped.id = ${id}
loop
   ins pedidos
   set tipo_pedido_id = ${tipo_pedido_requisicao_id}
   , estabelecimento_id = ${rec.estabelecimento_id}
   , cliente_id = ${rec.cliente_id}
   , fornecedor_id = ${rec.fornecedor_id}
   ;
   ins itens_pedidos
   set pedido_id = ${last.id}
   , item_pedido_venda_id = ${rec.item_pedido_id}
   , produto_id = ${rec.produto_id}
   , quantidade = 1
   ;
end-loop;
end-if;