Error while creating POs programmatically

Hi All,

I am programmatically trying to create POs in bulk, to accomplish that I have put the PO creation code in a loop. The code works perfectly for the first iteration of the loop, however gives error “Order number cannot be changed” in the second iteration. I’ve taken care of incrementing the PO number and all standard precautions are implemented. Can anyone suggest the reason behind the error.

I’m working on Ax 2009 and the PO creation code got from:

X++ Code to Create Purchase Order and Post the Invoice

What happens when you debug, does the loop pick up the next Order Number, or does the value stay the same in debugger?

Hi William,

Thank you for your reply!

I don’t know which field to refer for the order number.

Created a class and called it in a loop of a job, instead of looping the code within a job.