Can some one please tell me if there is anything wrong with my syntax. i am trying to change the unit price to zero on Sales line if a condition is met.
this is what i have:
If Not SalesLine.Insert(TRUE) Then
For some reason it fails on the above statement. I would appreciate your help.
Can you tell us what the error is?
Alternatively, try this instead:
IF SalesLine.INSERT(TRUE) THEN;
Depends - if the statement is made in a function, that returns nothing, then your “EXIT(FALSE)” will fail.
But munib00’s solution is the usual one, unless you want to make a break in the code.
Well, i cant proceed with the function if the price is not changed to 0. Thats why I have the Exit(false) statement in place.
My apologies, i didnt word the question right. I meant to say why is the unitprice on the sales line not being inserted or changed.
When a new sales order is created (programatically created) and a field called COR (credit on return) is checked on the Sales header, then the price is changed to 0. if the price is not changed, then i can’t proceed further. Hope this makes sense, i am really bad at explaining things.
If this is an existing sales line, you should do SalesLine.MODIFY, instead of SalesLine.INSERT.
It will always fail to insert the record, because there already is a record in the table, with the same values in the primary key fields.
Or do it like this…
IF NOT SalesLine.INSERT(TRUE) THEN
(You only need to make sure that no code in the insert- and modify-triggers will change the “unit price” away from 0.)
Thank you very much Alex, You are a Genius.
That was the problem, i was trying to insert instead of modify. What would i do with out you.