When Lookup then Need Non Editable Field

abhinavmehraabhinavmehra Member Posts: 34
Hello All,

I have My PO screen....
I need when I lookup to Receiving Location my ship to code fied work as Editable & Non Editable condition.

Scenario - I have 2 receiving Location 1) A - Default 2) B - Non-Default

When I choose 1) A - Default then I need Ship to code Editable & Lookup
When I choose 2) B - Non-Default then I need Ship to code field is Non-Editable & No Lookup


I wrote the code

where location is a variable of Location Table


location.SETRANGE(location.Distributor ,TRUE);
location.SETRANGE(location."Company Name" , COMPANYNAME);
IF FORM.RUNMODAL(0,location)= ACTION::LookupOK THEN BEGIN
IF location."Default Warehouse"=FALSE THEN
CurrForm."Shipment Method Code".EDITABLE(FALSE);

VALIDATE("Location Code" ,location.Code);

END;


But it gives the Non-Editable for every Location.....

Please give the suggestion Quickly


Thanks

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    where did you write this code?

    Did you try this code after validate?

    IF "Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE);

    is it working if you close and open the form?
  • abhinavmehraabhinavmehra Member Posts: 34
    Now i tried this code

    I am writing this code in Location Code of PO form in Onlookup trigger.


    loc.SETRANGE(loc.Distributor ,TRUE);
    loc.SETRANGE(loc."Company Name" , COMPANYNAME);
    IF FORM.RUNMODAL(0,loc)= ACTION::LookupOK THEN BEGIN
    VALIDATE("Location Code" ,loc.Code);

    IF loc."Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE);
    END;

    Its working

    But when I again select Default its still Non-Editable & lookup in also working in Ship to Code filed. I don't need lookup when i choose B Location.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Use
    CurrForm."Shipment Method Code" := NOT loc."Default Warehouse";
    inplace of
    IF loc."Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE);
  • vijay_gvijay_g Member Posts: 884
    Try this...
    IF loc."Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE)
    else
    CurrForm."Shipment Method Code".EDITABLE(TRUE);
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Use
    CurrForm."Shipment Method Code" := NOT loc."Default Warehouse";
    
    inplace of
    IF loc."Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE);

    it will do the same.
  • vijay_gvijay_g Member Posts: 884
    Use
    CurrForm."Shipment Method Code" := NOT loc."Default Warehouse";
    
    inplace of
    IF loc."Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE);

    it will do the same.
    it should be...
    CurrForm."Shipment Method Code".EDITABLE := NOT loc."Default Warehouse";
  • abhinavmehraabhinavmehra Member Posts: 34
    Hey thanks Mohana

    Its Working Good....

    Now What I'll do for Lookup...??

    Becoz if its Non-Editable I also Need No LookUp.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    vijay_g wrote:
    Use
    CurrForm."Shipment Method Code" := NOT loc."Default Warehouse";
    
    inplace of
    IF loc."Default Warehouse"=FALSE THEN
    CurrForm."Shipment Method Code".EDITABLE(FALSE);

    it will do the same.
    it should be...
    CurrForm."Shipment Method Code".EDITABLE := NOT loc."Default Warehouse";

    Offcource..good Catch :thumbsup:
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Hey thanks Mohana

    Its Working Good....

    Now What I'll do for Lookup...??

    Becoz if its Non-Editable I also Need No LookUp.

    loc.get("Location Code");
    IF NOT loc."Default Warehouse" THEN
    EXIT;
    IF FORM.RUNMODAL(0,ShpMetCode)= ACTION::LookupOK THEN
    VALIDATE("Shipment Method Code" ,ShpMetCode.Code);

    try something like this
    loc is Location table
    shpmetcode is Shipment Method table
  • DenSterDenSter Member Posts: 8,305
    No.... this is going all wrong. Data validation should NEVER be on the form level. The data validation part (getting the code, looking up the value, stuff like that) should be in OnValidate on the table level. Then the layout part (setting the control to editable, bold, colors) can go into OnAfterValidate of the form.

    Putting all of this logic on the form is the WRONG thing to do.
Sign In or Register to comment.