Item description of first sales line in sales header

lavanyaballurgilavanyaballurgi Member Posts: 235
Hello expert,

as the subject says I am trying to fill a new field in sales header with the item description of first sales line (in same sales order). Here is my code (which doesnt work :( )
Please advice what I am missing

//CR -013+++
IF ("Line No." = 10000) THEN BEGIN
so.GET("Document Type"::Order,"Document No.");
IF so.FINDSET THEN BEGIN
so.Description := Item.Description;
so.MODIFY;
END;
END;
//CR -013---

"Description 2" := Item."Description 2";

Answers

  • hawkeyehawkeye Member Posts: 51
    First of all - don´t do a get and then a findset. It doesn´t make sence.

    Then you need to get the ItemRec before you can make the

    "so.Description := Item.Description;"

    The Code Could look like the following.

    IF ("Line No." = 10000) AND (Type = Type::Item) THEN
    IF (so.GET("Document Type","Document No.")) AND Item.get("No.") then begin
    so.VALIDATE(Description,Item.Description);
    so.MODIFY(TRUE);
    END;


    Edit:
    I don´t like the filter on Line No 10000 - How can you be sure this is the first line of the order?
    br

    Hawkeye
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    THanks for the clarification Hawkeye.. Even I agree that filter on 10000 line number is not 100% correct but then what alternative can I use?
    My aim is to get the first line of sales line.
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    Well its not working... I put this code here -

    No. - OnValidate()

    Hope this is the right place
  • amr_wafaamr_wafa Member Posts: 23
    You can create a field in the Sales Header field type = FlowField with Type = Lookup

    Lookup("Sales Line".Description WHERE (Document Type=FIELD(Document Type),Document No.=FIELD(No.),Line No.=CONST(10000)))

    but you need to put CurrForm.UPDATE after validating the Item No.

    so you dont need any coding at all.
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    Oh sorry it works... but i need to navigate away from the form. THanks alot. If you can provide me an alternative to LINE NO. 10000 it would be a 100% resolved issue :D
  • amr_wafaamr_wafa Member Posts: 23
    Oh sorry it works... but i need to navigate away from the form. THanks alot. If you can provide me an alternative to LINE NO. 10000 it would be a 100% resolved issue :D

    one question, if the user sorted Descending then what should happen.

    any way, Try Max instead of Lookup and remove the Line No. filter.
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    Well the users do not sort at all.. its always the first line description they are interested into but like you said the problem lies in LINE NO. 10000
    And using MAX without LINE NO. filter is giving random result i.e. description of LINE NO. 80000 or 30000... cant find any pattern.cant we sort the salse line on basis on Line No & select the first/smallest LINE NO.?
  • lavanyaballurgilavanyaballurgi Member Posts: 235
    this works fine -

    Lookup("Sales Line".Description WHERE (Document Type=FIELD(Document Type),Document No.=FIELD(No.),Type=FILTER(item)))

    thanks for your time & it was a great learning..
Sign In or Register to comment.