Create copy function

Hi dear users,

i would like to add a Copy function to duplicate “sales Program lines” of one already existing “Program order” to a new created “Program order” to avoid adding line by line every time i create a new one and without setting any filter or something like that.

can somebody help me please.

i have created a Report for the function that i have created on the “Program Order Card”.

P.Keys : Program No, Program Type.

Thank you in advance.

Did you write any code? what problems are you facing?

hi,
no i still did not write any code. i want to start but i don’t know how.

Please don’t expect code from forum.
check Production BOM card. It has copy BOM action.
Try to investigate and write some code and let us know if you have any issues.

no i don’t expect Code from Forum, i just want to see if someone has already implemented this function before and talk about it to get ideas.
i will share my evaluation! thanks

thank you for understanding. Good luck…

hi,

somebody know this error message :

when i click on the Copyfunction i get it.

Microsoft Dynamics NAV

The Sales Program Header does not exist. Identification fields and values: No.=’’

OK

Are you using any GET function?
Can you show code?

hi,
i just got back to this Function and i dont get the ERROR msg anymore.

---- i have code in a Codeunit/function “copyProgramLineNew” ----------------

FUNCTION :
CopyProgramLineNew(pFromProgramNo : Code[20];pHeaderCodeNo : Code[20]) : Boolean
CODE :
FromProgOrderLine.RESET;
FromProgOrderLine.SETRANGE(“Program No.”, pFromProgramNo);
IF FromProgOrderLine.FINDSET THEN BEGIN
REPEAT
ToProgramOrderLine.INIT;
ToProgramOrderLine.TRANSFERFIELDS(ProgOrderLine);
ToProgramOrderLine.“Program No.” := pHeaderCodeNo;
ToProgramOrderLine.VALIDATE(Type, FromProgOrderLine.Type);
ToProgramOrderLine.VALIDATE(“No.”, FromProgOrderLine.“Program No.”);
ToProgramOrderLine.INSERT(TRUE);
UNTIL FromProgOrderLine.NEXT = 0;
EXIT(TRUE);
END;
EXIT(FALSE);

— i created a report/function "SEtSalesProgramHHeader ----------------------------

FUNCTION :
SetSalesProgramHeader(VAR NewSalesProgramHeader : Record “Sales Program Header”)
CODE :
SalesProgramHeader := NewSalesProgramHeader

and on the Page where i want to show the Copy Document function i have this code : ---------------------

FUNCTION :
CopyOrderProgramLines - OnAction()

CODE:
CopyProgramOrderMgtRep.SetSalesProgramHeader(Rec);
CopyProgramOrderMgtRep.RUNMODAL;
CLEAR(CopyProgramOrderMgtRep);
CurrPage.UPDATE(FALSE);

i know that i need to call my codeunit inside the report in OnPreReport() but i dont know how.

maybe something is missing.

  1. Call CopyProgramLineNew(pFromProgramNo,pHeaderCodeNo) functon from OnRun trigger of the codeunit.
  2. ToProgramOrderLine.TRANSFERFIELDS(ProgOrderLine) change into ToProgramOrderLine.TRANSFERFIELDS(FromProgOrderLine);

Hi Dileepa,
thank you for your reaction.
its not working unfortunately!!

You have to debug and go through the code to see, where you are missing the logic.

I believe, If you are implementing some thing which is already implemented and trying to make a copy of this then first thing what I will do is I will try to understand the functionality that actually I am trying to copy. If copying source code is yet not clear to me then how come I can make a copy of that.