How can the system auto generated field value is created on purchase order?

I want to set an autogenerated value to a field like an invoice number using the set_value method is there any mechanism to do that?

Do you mean naming series?