Creating Purchase Orders from C/AL

Hello. I have to create a purchase order from c/al-code. For the Header it doesn’t seem to be a problem (for 1 to 4 the record is always outRec.), 1.init,2.doc.type : order,3.validate(“posting date”,today),4.validate(“buy from vendor no.”,myNo.),5.commit; If I execute only the code above the header is created correctly and can also be deleted afterwards. Now I have to add some lines: 1.purchLine.init; 2.purchLine.“document type”:=outrec.“document type” 3.purchLine.“document no.”:=outrec.“document no.” 4.purchLine.validate(type,purchLine.type::“Account (g/l)”); 5.purchLine.validate(“no.”,MyAccountNo); 6.purchLine.validate(quantity,1); 7.purchLine.validate(“Direct Unit Cost”,MyCosts) 8.purchLine.“shipment no.”:=xyz; (field I added) 9.purchLine.insert(true); 10.commit; Everything from 1 to 10 is between a repeat…until but it also doesn’t work without it (with only the first found record). The problem is: the first purchase line is created (apparently correct looking at the purchase order), but if i want to delete the created line, Dr.Watson reports a STACK OVERFLOW error and Attain is terminated. There is no way to erase that line, also from the object designer its impossible. Could the error be related to the new feature of Attain (Dimensions, I couldn’t understand how they are mantained) or is there some other mistake. Thank you very much in advance. Martin

Martin, You missed PurchLine.“Line No.”. In standard system it is maintained by the purchase line form, by auto split key property. When you insert records from code, you have to set it manually (in 10,000 intervals per standard) Ciao, Alex

Alex is right. But there is NO reason for the application to end with a stack overflow as long as 0 (line no.) is an integer, and, as far as I know, 0 IS integer. Regards Walter

Thank you very much, now its working, I really forgot the line no.-field. Does someone know if I have to consider the dimensions anyway (I dont need their functionality)?

If you are not using the Dimensions, you can just leave those fields blank. Dave Studebaker Liberty Grove Software A Navision Services Partner