Setting table field's property EDITABLE in code

ArchyArchy Member Posts: 70
Hi all!

Is it possible, to set field property EDITABLE (or VISIBLE or ENABLED) in code of table? when i tried to write: field1.EDITABLE := FALSE i received following error message: "The variable is not a record. 'Variable.Field' is invalid". But field1 is not a variable, it is a field in a table!

Thanks!

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    You can set a field editable runtime on a form.
    Currform.Control.Editable(Boolean)
    
  • ArchyArchy Member Posts: 70
    You can set a field editable runtime on a form.
    Currform.Control.Editable(Boolean)
    

    But in this case field doesn't update till I go to another record and go back. :( currform.update didn't help.. Any other ideas? :-s
  • kinekine Member Posts: 12,562
    It is table form or card form?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • ArchyArchy Member Posts: 70
    It is a table form and i need it to update if user has entered value in another field - it can be when new record is entered or existing record is updating. if Field2 <> '' then Field1.enabled := true ELSE Field1.enabled := false. But the form doesn't refresh controls. :(
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Have you tried the OnAfterValidate trigger of the control that determines the visibility?
  • kinekine Member Posts: 12,562
    It is not good to work with Editable and Enabled properties on table form. (Whole column is disabled etc.). Try to do it in another way - for example when entering value into the "disabled" column, test the condition and show error that user must firstly fill another field...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, that's the Nav way. Test the value instead of enabling controls.
  • ArchyArchy Member Posts: 70
    We have such condition:
    if Field1 <> '' then
    Field2.ENABLED := FALSE
    else
    Field2.ENABLED := FALSE;

    In trigger OnAfterValidate for Field1 I added such code:

    IF Field1 <> '' THEN BEGIN
    CurrForm.Field2.EDITABLE := TRUE;
    CurrForm.UPDATECONTROLS;
    END ELSE BEGIN
    CurrForm.Field2.EDITABLE := FALSE;
    CurrForm.UPDATECONTROLS;
    END;

    But it doesn't work! :(
  • ArchyArchy Member Posts: 70
    Oh, I have told wrong, it's not table form, it's card form.. :oops:
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    UPDATECONTROLS is for the captionclass.

    You can try
    CurrForm.Field2.EDITABLE(Field1 <> '' );
    

    in the OnAfterValidate trigger of the Field1 control.
    It should work without an update
  • ArchyArchy Member Posts: 70
    It doesn't work! :cry:
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    What is the value of the Editable property in the table? If you want to change it at form-level it should be editable in the table.

    It should also be in the OnAftergetCurrRecord trigger. (the code that is)

    Best is to make a function like in the customer card.
  • ArchyArchy Member Posts: 70
    What is the value of the Editable property in the table? If you want to change it at form-level it should be editable in the table.

    It should also be in the OnAftergetCurrRecord trigger. (the code that is)

    Best is to make a function like in the customer card.

    In table editable is TRUE...
    Actually, I would like to find example and take solution from it, but I can't find it. I didn't find in Customer Card such a thing.. :( It seems, in Customer Card controls Editable properties aren't changed at runtime.. Am I wrong?
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    This is true.

    But you can make a test in a cronus database with the customer card.

    Open it, click on the Name field.

    In the OnAfterValidate trigger put this code
    CURRFORM.Address.EDITABLE(Name = 'Mark');
    

    This shoud work.
  • ArchyArchy Member Posts: 70
    When I delete the value from Field1, Field2 became uneditable, as I wish. But, when enter value into Field1, Field2 doesn't became Editable before leave this record and arrive on it. In first situation Form's OnAfterGetRecord trigger runs, when I enter value it doesn't run. I can't understand, why so. :( Please, help!
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    When you change the value the OnAfterValidate triggers is run, so your code needs to be in 2 places!

    Thats why a function is the best solution.
  • ArchyArchy Member Posts: 70
    May be someone can tell, what may call table's OnAfterGetRecord trigger in cases when we didn't leave current record? :| May be LOCKTABLE can cause this? Or function calls? Or, maybe, codeunit calls?
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    I think the working of the form triggers is not clear to you.

    To see what triggers are used you can put messages into the trigger and try what triggers are used when browsing through record and changing values.

    LOCKTABLE or codeunits are definately not calling form triggers.
  • ArchyArchy Member Posts: 70
    ](*,)

    But thanks anyway! :)
  • ArchyArchy Member Posts: 70
    Oh, i found! When deleting value from this field - triggers OnValidate, OnAfterGetRecord and OnAfterValidate are running. When enter new value, the NO trigger runs!
  • SavatageSavatage Member Posts: 7,142
    I'm trying something similar but I can't seem to get it to work

    Every Sales Header has a boolean "Internet order"

    If the "Internet order" = True then I want the "Unit Price" field on the Sales Line to be editable.
    OnBeforeInput<>
    IF SalesHeader."Internet Order" THEN
    CurrForm."Unit Price".UPDATEEDITABLE(TRUE);
    

    But I doesn't seem to work. It's always UNEDITABLE with this code.

    Am I using the wrong trigger?

    Also tried
    CurrForm."Unit Price".EDITABLE(SalesHeader."Internet Order" = TRUE);
    
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Is the internet order a static field? Then you'll only need to change the onaftergetcurrrecord trigger or the FORM with

    CurrForm."Unit Price".EDITABLE("Internet Order");

    If the Internet Order field is also an editable field you'll also need to change the OnAfterValidate trigger if the FIELD with the same code.

    Good luck!

    If nesesairy I'm willing to make a small example and mail it to you. 8)
  • SavatageSavatage Member Posts: 7,142
    We import our Internet orders via a dataport.
    The imported orders set the "Internet Order" Checkbox to YES on the sales header

    The Internet Order Checkbox is on the sales header.
    We do not want the prices to be changed for any regular order but sometimes we need to adjust the price on the internet orders.

    So the internet order flag is on the sales header and we want to lockdown the sales line "Unit Price" if it's not an internet order

    My Current Code is
    OnAfterGetCurrRecord()
    CurrForm."Unit Price".EDITABLE(SalesHeader."Internet Order");
    

    But the Unit Price Is uneditable if it's an internet order or not.
    Does this work differently because it's a subform?

    note:The Internet Order boolean is not editable.
  • SavatageSavatage Member Posts: 7,142
    Update - So I added the "Internet Order" Boolean to the sales line also and the code works fine. It was when trying to pull the value of the boolean from the sales header that didn't work.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • SavatageSavatage Member Posts: 7,142
    yes i got it to work but anyone have a specific reason why it wouldn't work if asking the code to look at the header and give me what i needed?
  • kinekine Member Posts: 12,562
    When (where) you are getting the value into SalesHeader variable?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • O-SeeO-See Member Posts: 4
    I have a table form, in which I have created a global Option and a boolean.
    Depending on if the boolean is true or not, the textbox displaying the Option should be Enabled or disabled.

    As far as i know the CurrForm only displays items in the table attached to the form.

    Do you have any suggestions to how I can access the control on the table ?

Sign In or Register to comment.