How can i create a new variable from another type

i try to create a new variable from another, here is the piece of code:
o = %NA.DB.Schema.ClaimField{o | ccid = 5000 | qual_ccid = 5000 | parent_ccid = 5000 }

and it throw me a error with the pipe.

You only need one pipe, and you should be using key: instead of key =.

o = %NA.DB.Schema.ClaimField{o | ccid: 5000, qual_ccid: 5000, parent_ccid: 5000}

You can also omit the NA.DB.Schema.ClaimField and still get a struct back (as long as o is a struct).

o = %{o | ccid: 5000, qual_ccid: 5000, parent_ccid: 5000}

Still the same problem, it says undefined function o/0.

How are you setting the original o variable? Is it in the same scope as the line you gave above?

here is the fucntion

defp filter_outgoing_class(incomings, outgoings) do
Enum.map(incomings, fn i ->
if Enum.any?(outgoings, fn o -> o.ccid == i.ccid end) do
%{o | ccid: 5000, qual_ccid: 5000, parent_ccid: 5000}
else
i
end
end)
end

this fucntion iterate two list for compare if one element of another has the ccid, if is there create another variable with the new values. but it thosen’t work.

o isn’t in scope. It is scoped to the function you gave to Enum.any?/2.

Try this instead:

defp filter_outgoing_class(incomings, outgoings) do 
  Enum.map(incomings, fn i -> 
    if o = Enum.find(outgoings, fn o -> o.ccid == i.ccid end) do
      %{o | ccid: 5000, qual_ccid: 5000, parent_ccid: 5000}
    else
      i 
    end
  end)
end

https://hexdocs.pm/elixir/Enum.html#find/3