Copy fields to a form

supp85
Member Posts: 76
Hello,
can anyone help me please, I have created a command button and within the onPush trigger i have inserted the following code to copy across certain fields from the sales order to another form (build schedule) however it doesn't seem to be working it creates a new record within the new form but all the fields are blank:
SalesHeader.SETRANGE("Document Type", "Document Type"::Order);
SalesHeader.SETRANGE("No.", SalesLine."Document No.");
SalesLine.SETRANGE(SalesLine.Type, SalesLine.Type::ITEM);
IF (SalesLine.FIND('-')) AND (SalesLine."To Build" = TRUE) THEN BEGIN
BuildSchHead.INIT;
SalesHeader."No." := BuildSchHead."Sales Order No.";
SalesHeader."Bill-to Name" := BuildSchHead."Customer Name";
REPEAT
BuildSchLine."Item No." := SalesLine."No.";
BuildSchLine.Description := SalesLine.Description;
BuildSchLine.Qty := SalesLine.Quantity;
BuildSchHead.INSERT(TRUE);
UNTIL BuildSchLine.NEXT = 0;
END;
MESSAGE('Build Schedule %1 has been created',BuildSchHead."No.");
Any ideas please?
can anyone help me please, I have created a command button and within the onPush trigger i have inserted the following code to copy across certain fields from the sales order to another form (build schedule) however it doesn't seem to be working it creates a new record within the new form but all the fields are blank:
SalesHeader.SETRANGE("Document Type", "Document Type"::Order);
SalesHeader.SETRANGE("No.", SalesLine."Document No.");
SalesLine.SETRANGE(SalesLine.Type, SalesLine.Type::ITEM);
IF (SalesLine.FIND('-')) AND (SalesLine."To Build" = TRUE) THEN BEGIN
BuildSchHead.INIT;
SalesHeader."No." := BuildSchHead."Sales Order No.";
SalesHeader."Bill-to Name" := BuildSchHead."Customer Name";
REPEAT
BuildSchLine."Item No." := SalesLine."No.";
BuildSchLine.Description := SalesLine.Description;
BuildSchLine.Qty := SalesLine.Quantity;
BuildSchHead.INSERT(TRUE);
UNTIL BuildSchLine.NEXT = 0;
END;
MESSAGE('Build Schedule %1 has been created',BuildSchHead."No.");
Any ideas please?
0
Comments
-
-
Thank you for your reply Sandeep, but it didn't work.0
-
any ideas? Yes, we change your source ;-)
This is your old source:SalesHeader.SETRANGE("Document Type", "Document Type"::Order); SalesHeader.SETRANGE("No.", SalesLine."Document No."); SalesLine.SETRANGE(SalesLine.Type, SalesLine.Type::ITEM); IF (SalesLine.FIND('-')) AND (SalesLine."To Build" = TRUE) THEN BEGIN BuildSchHead.INIT; SalesHeader."No." := BuildSchHead."Sales Order No."; SalesHeader."Bill-to Name" := BuildSchHead."Customer Name"; REPEAT BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchHead.INSERT(TRUE); UNTIL BuildSchLine.NEXT = 0; END;
This is the new source (i hope the Button is on the Sales Order Form and not in the subform):SalesLine.reset; SalesLine.setrange("Document Type",Rec."Document Type"); SalesLine.setrange("Document no.",Rec."No."); SalesLine.SETRANGE(Type,SalesLine.Type::ITEM); SalesLine.SETfilter("No.",'<>'''''); SalesLine.setrange("To Build",true); if SalesLine.findset then begin if not BuildSchHead.get(PRIMARY KEY VALUES) then begin BuildSchHead.INIT; BuildSchHead."Sales Order No." := Rec."No."; BuildSchHead."Customer Name" := "Bill-to Name"; //here the other field in BuildSchHead table BuildSchHead.insert; end; //what is, if the Rec exist? a modify or what? repeat if not BuildSchLine.get(PRIMARY KEY VALUES) then begin BuildSchLine.init; BuildSchLine."Primary key Fields" := "Primary KEY VALUES" BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchLine.INSERT(TRUE); //the true only if you have soure in the Insert Trigger end; //what is, if the Rec exist? a modify or what? until SalesLine.next = 0; end;
RegardsDo you make it right, it works too!0 -
Thank you very much Garak that worked great I took your Modify comments on board and put code in to cater for existing records. Thanks again0
-
no problem and welcomeDo you make it right, it works too!0
-
Hello again,
I seem to be having problems with getting the record to modify of it exists, the code i have added is as follows;IF SalesLine."To Build" = FALSE THEN ERROR('Unable to create Build Schedule please ensure all fields are correctly entered') IF SalesLine.FINDSET THEN BEGIN IF NOT BuildSchHead.GET("No.") THEN BEGIN BuildSchHead.INIT; BuildSchHead."Sales Order No." := Rec."No."; BuildSchHead."Customer Name" := "Bill-to Name"; BuildSchHead.INSERT(TRUE); END ELSE IF NOT BuildSchHead.INSERT THEN BuildSchHead."Customer Name" := "Bill-to Name"; BuildSchHead.MODIFY(TRUE); REPEAT IF NOT BuildSchLine.GET('Build No.','Item No.') THEN BEGIN BuildSchLine.INIT; BuildSchLine."Build No." := BuildSchHead."No."; BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchLine.INSERT(TRUE); END ELSE IF NOT BuildSchLine.INSERT THEN BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchLine.MODIFY(TRUE); UNTIL SalesLine.NEXT = 0; END; MESSAGE('Build Schedule %1 has been created',BuildSchHead."No.");
I have also tried IF NOT INSERT THEN MODIFY, but that does not work either?0 -
IF NOT BuildSchLine.INSERT THEN //////////////////SHOULD THERE BE A "BEGIN" HERE? BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchLine.MODIFY(TRUE);
see the comment, i don't know if this is the problem, as i didn't read carefully your code, but it is potentially a serious bug, if i'm right0 -
Thank you for your reply, i have tired it but still not working0
-
Yes that has been corrected.0
-
:shock: what the hell is this?!?!
IF NOT BuildSchLine.GET('Build No.','Item No.') THEN BEGIN
you are doing a GET with 'Build No.' and 'Item No.' strings. i mean, these strings AS IS
have you really got a line that have "build no." = 'build no." and "item no." = 'item no.'?! :shock:
i don't think so, maybe you want to doIF NOT BuildSchLine.GET("Build No.","Item No.") THEN BEGIN
anyway, i don't think this will make your application work correctly, there are some other problems in the code.0 -
SalesLine.reset; SalesLine.setrange("Document Type",Rec."Document Type"); SalesLine.setrange("Document no.",Rec."No."); SalesLine.SETRANGE(Type,SalesLine.Type::ITEM); SalesLine.SETfilter("No.",'<>'''''); SalesLine.setrange("To Build",true); IF SalesLine.FINDSET THEN BEGIN IF NOT BuildSchHead.GET("No.") THEN BEGIN BuildSchHead.INIT; BuildSchHead."Sales Order No." := Rec."No."; BuildSchHead."Customer Name" := "Bill-to Name"; BuildSchHead.INSERT(TRUE); END ELSE begin // IF NOT BuildSchHead.INSERT THEN begin //USELESS, as you already tested that the record exists BuildSchHead."Customer Name" := "Bill-to Name"; BuildSchHead.MODIFY(TRUE); end; REPEAT IF NOT BuildSchLine.GET(BuildSchHead."No.",SalesLine."No.") THEN BEGIN BuildSchLine.INIT; BuildSchLine."Build No." := BuildSchHead."No."; BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchLine.INSERT(TRUE); END ELSE begin // IF NOT BuildSchLine.INSERT THEN //USELESS, see above BuildSchLine."Item No." := SalesLine."No."; BuildSchLine.Description := SalesLine.Description; BuildSchLine.Qty := SalesLine.Quantity; BuildSchLine.MODIFY(TRUE); end; UNTIL SalesLine.NEXT = 0; END; MESSAGE('Build Schedule %1 has been created',BuildSchHead."No.");
This should be correct, (what is the "rec"?) you should check the GET function in the online help
hope to be helpful0 -
Thank you for your reply Belias however its still not working0
-
Rec is sales header, this code has been written within a command button0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions