Assigning a field type option to a field type option

Hello,

I have two record variables: SalesLines and NewLines which each has a field (Type) of type option (G/L Account and Item). I want to assign NewLines to SalesLines with the VALIDATE function, but it doesnt seem to work. This is my code:

SalesLines:VALIDATE(Type, NewLines.Type);

SalesLines.INSERT(TRUE)

I have also tried:

SalesLines:VALIDATE(Type, SalesLines.Type::NewLines.Type);

SalesLines.INSERT(TRUE)

Can anyone see the problem?

Hi Petan,

  1. You must ensure that the option-string property of the 2 fields in question is identical.
    What is stored in the database is only an integer, and the text you see in the client, is “attached” at runtime.
    So if salesline.type has option-string: G/L Account,Item, and newline.type has option-string: Item,G/L Account, then doing what you do, will actually assign the opposite value.

  2. If Salesline is already inserted before hand, you must use SalesLines.MODIFY.

  3. The correct syntax is SalesLines.VALIDATE, not Saleslines:VALIDATE (with a colon)

otherwise what you tried first should work.

Thanks, sander7!

Thats the problem, my option strings are not identical.

Can I somehow change the integer that defines the option? Could I let one of the options strings start with 2 or 3? Or is there another easy way out without having to hardcode or adding elements to the option string?

Thanks in advance!

You can’t change the integer value choise.
It always start with 0 for the first choice, 1 for the second …

The optionstring can contain “empty” choises.
e.g. look at “Posting Type” in table 81.
But i wouldn’t recommend that, as the user can just as well choose one of the blank values, as they can choose the ones you want them to use.
Then you have to code some check instead.

I think you can use CASE, since you don’t nessecary have to attend all possible values…
So something like this could be done:
CASE NewLine.Type OF
NewLine.Type::“G/L Account”: SalesLines`.VALIDATE(Type,SalesLines.Type::“G/L Account”);
NewLine.Type::Item: SalesLines.VALIDATE(Type,SalesLines.Type::Item);
END;

Ok. Thanks a lot for your help!