Options

Coding Error.

Rajat_MRajat_M Member Posts: 34
Hello,

I have created two fields in the 'Item Card' page, i.e. Item Type & Item Color. Both are option fields.In Item Type field I declared three options:1.Paper, 2.Ink, 3.Chemical & in Item Color I declared 1.White & 2.Red options. I want to add some functionalities on those fields i.e. whenever a user selects 'Ink' option from the Item Type field it prompts the user to select at least one color from the Item Color field.If the user doesn't select any color then it'll show an error msg. I hv write the following code within the 'OnValidate' trigger of Item Type field:

if "Item Type"="Item Type"::Ink then

"Item Color":="Item Color"::Red,White

else

Errror('Please select a color');

But it shows syntax error. Please help me out.

Best Answer

  • Options
    AntidotEAntidotE Member Posts: 61
    edited 2016-04-07 Answer ✓
    If I understand correctly you want to show something as prompt with two options to select.
    Your code should look roughly like this:
    IF "Item Type" = "Item Type"::Ink THEN
      SelectedResult := STRMENU('Red,White',1,'Select color');
    IF SelectedResult = 0 THEN
      ERROR('You have to select color');
    "Item Color" := SelectedResult - 1;
    

    And better use this code on the page, because if you use it on OnValidate on table, you can encounter situation when validating by code (not by user) will throw you big error about transaction :smile:
    It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.

Answers

  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    Syntax error is in this line
    "Item Color":="Item Color"::Red,White

    But I didn't understand why you are writing code in Item Type Onvalidate.

    It will execute immediately after user selecting Ink in Item Type.
    Probably you should show a message that Please select colour etc. if item type is Ink.

    You can use Blocked field here to make some fields mandatory
    1. On Item Type validate set Blocked field to Yes
    2. On Item Color field validate set it to no
    3. If user tries to make blocked field then check whether user has entered Item Colour and if not show error.
  • Options
    AntidotEAntidotE Member Posts: 61
    edited 2016-04-07 Answer ✓
    If I understand correctly you want to show something as prompt with two options to select.
    Your code should look roughly like this:
    IF "Item Type" = "Item Type"::Ink THEN
      SelectedResult := STRMENU('Red,White',1,'Select color');
    IF SelectedResult = 0 THEN
      ERROR('You have to select color');
    "Item Color" := SelectedResult - 1;
    

    And better use this code on the page, because if you use it on OnValidate on table, you can encounter situation when validating by code (not by user) will throw you big error about transaction :smile:
    It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.
  • Options
    Rajat_MRajat_M Member Posts: 34
    AntidotE wrote: »
    If I understand correctly you want to show something as prompt with two options to select.
    Your code should look roughly like this:
    IF "Item Type" = "Item Type"::Ink THEN
      SelectedResult := STRMENU('Red,White',1,'Select color');
    IF SelectedResult = 0 THEN
      ERROR('You have to select color');
    "Item Color" := SelectedResult - 1;
    

    And better use this code on the page, because if you use it on OnValidate on table, you can encounter situation when validating by code (not by user) will throw you big error about transaction :smile:

    Thanks a lot for the code man..It just hits the bull’s eye..!! :smiley:
Sign In or Register to comment.