Hi
I am trying to copy job task from one job to another using the copy job task function
Its giving me an error " the following SQL error was unexpected. failed to convert parameter value from a SqlDecimal to a string"
*This post is locked for comments
Checking a clean NAV 2013 database and I don't see any code in Job Task No. OnValidate trigger: is it still empty in your environment?
Please check also "Job No." field of "Job Planning Line" table and "Job Task No." field of "Job Task" table have the same type (Code20) by default.
hi
i did debugg on the codeunit 1006
the yellow arrow pointed at this line
VALIDATE("Job Task No.",TargetJobTask."Job Task No.");
the error only happens when i use source as job planning lines inside the copy job task from function
if i keep the source blank , it copies the job task lines successfully.
here is the code
CopyJob(SourceJob : Record Job;TargetJobNo : Code;TargetJobDescription : Text;TargetJobBillToCustomer : Code)
TargetJob.VALIDATE("No.",TargetJobNo);
TargetJob.TRANSFERFIELDS(SourceJob,FALSE);
TargetJob.INSERT(TRUE);
IF TargetJobDescription <> '' THEN
TargetJob.VALIDATE(Description,TargetJobDescription);
IF TargetJobBillToCustomer <> '' THEN
TargetJob.VALIDATE("Bill-to Customer No.",TargetJobBillToCustomer);
TargetJob.VALIDATE(Status,TargetJob.Status::Planning);
IF CopyDimensions THEN
CopyJobDimensions(SourceJob,TargetJob);
CopyJobTasks(SourceJob,TargetJob);
IF CopyPrices THEN
CopyJobPrices(SourceJob,TargetJob);
TargetJob.MODIFY;
CopyJobTasks(SourceJob : Record Job;TargetJob : Record Job)
SourceJobTask.SETRANGE("Job No.",SourceJob."No.");
CASE TRUE OF
(JobTaskRangeFrom <> '') AND (JobTaskRangeTo <> ''):
SourceJobTask.SETRANGE("Job Task No.",JobTaskRangeFrom,JobTaskRangeTo);
(JobTaskRangeFrom <> '') AND (JobTaskRangeTo = ''):
SourceJobTask.SETFILTER("Job Task No.",'%1..',JobTaskRangeFrom);
(JobTaskRangeFrom = '') AND (JobTaskRangeTo <> ''):
SourceJobTask.SETFILTER("Job Task No.",'..%1',JobTaskRangeTo);
END;
IF SourceJobTask.FINDSET THEN
REPEAT
TargetJobTask.INIT;
TargetJobTask.VALIDATE("Job No.",TargetJob."No.");
TargetJobTask.VALIDATE("Job Task No.",SourceJobTask."Job Task No.");
TargetJobTask.TRANSFERFIELDS(SourceJobTask,FALSE);
TargetJobTask.INSERT(TRUE);
CASE TRUE OF
JobPlanningLineSource = JobPlanningLineSource::"Job Planning Lines":
CopyJobPlanningLines(SourceJobTask,TargetJobTask);
JobPlanningLineSource = JobPlanningLineSource::"Job Ledger Entries":
CopyJLEsToJobPlanningLines(SourceJobTask,TargetJobTask);
END;
IF CopyDimensions THEN
CopyJobTaskDimensions(SourceJobTask,TargetJobTask);
UNTIL SourceJobTask.NEXT = 0;
CopyJobPlanningLines(SourceJobTask : Record "Job Task";TargetJobTask : Record "Job Task")
SourceJob.GET(SourceJobTask."Job No.");
CASE TRUE OF
(JobTaskDateRangeFrom <> 0D) AND (JobTaskDateRangeTo <> 0D):
SourceJobTask.SETRANGE("Planning Date Filter",JobTaskDateRangeFrom,JobTaskDateRangeTo);
(JobTaskDateRangeFrom <> 0D) AND (JobTaskDateRangeTo = 0D):
SourceJobTask.SETFILTER("Planning Date Filter",'%1..',JobTaskDateRangeFrom);
(JobTaskDateRangeFrom = 0D) AND (JobTaskDateRangeTo <> 0D):
SourceJobTask.SETFILTER("Planning Date Filter",'..%1',JobTaskDateRangeTo);
END;
SourceJobPlanningLine.SETRANGE("Job No.",SourceJobTask."Job No.");
SourceJobPlanningLine.SETRANGE("Job Task No.",SourceJobTask."Job Task No.");
CASE JobPlanningLineType OF
JobPlanningLineType::Schedule:
SourceJobPlanningLine.SETRANGE("Line Type",SourceJobPlanningLine."Line Type"::Schedule);
JobPlanningLineType::Contract:
SourceJobPlanningLine.SETRANGE("Line Type",SourceJobPlanningLine."Line Type"::Contract);
END;
SourceJobPlanningLine.SETFILTER("Planning Date",SourceJobTask.GETFILTER("Planning Date Filter"));
IF SourceJobPlanningLine.FINDSET THEN
REPEAT
WITH TargetJobPlanningLine DO BEGIN
INIT;
VALIDATE("Job No.",TargetJobTask."Job No.");
VALIDATE("Job Task No.",TargetJobTask."Job Task No.");
IF JobPlanningLine.GET("Job No.","Job Task No.",SourceJobPlanningLine."Line No.") THEN BEGIN
NextPlanningLineNo := JobPlanningLine."Line No.";
JobPlanningLine.NEXT;
NextPlanningLineNo := (NextPlanningLineNo + JobPlanningLine."Line No.") / 2;
END ELSE
NextPlanningLineNo := SourceJobPlanningLine."Line No.";
VALIDATE("Line No.",NextPlanningLineNo);
TRANSFERFIELDS(SourceJobPlanningLine,FALSE);
"Remaining Qty." := 0;
"Remaining Qty. (Base)" := 0;
"Remaining Total Cost" := 0;
"Remaining Total Cost (LCY)" := 0;
"Remaining Line Amount" := 0;
"Remaining Line Amount (LCY)" := 0;
"Qty. Posted" := 0;
"Qty. to Transfer to Journal" := 0;
"Posted Total Cost" := 0;
"Posted Total Cost (LCY)" := 0;
"Posted Line Amount" := 0;
"Posted Line Amount (LCY)" := 0;
"Qty. to Transfer to Invoice" := 0;
"Qty. to Invoice" := 0;
INSERT(TRUE);
IF Type <> Type::Text THEN BEGIN
ExchangeJobPlanningLineAmounts(TargetJobPlanningLine,SourceJob."Currency Code");
IF NOT CopyQuantity THEN
VALIDATE(Quantity,0)
ELSE
VALIDATE(Quantity);
MODIFY;
END;
END;
UNTIL SourceJobPlanningLine.NEXT = 0;
CopyJLEsToJobPlanningLines(SourceJobTask : Record "Job Task";TargetJobTask : Record "Job Task")
SourceJob.GET(SourceJobTask."Job No.");
TargetJobPlanningLine.SETRANGE("Job No.",TargetJobTask."Job No.");
TargetJobPlanningLine.SETRANGE("Job Task No.",TargetJobTask."Job Task No.");
IF TargetJobPlanningLine.FINDLAST THEN
NextPlanningLineNo := TargetJobPlanningLine."Line No." + 10000
ELSE
NextPlanningLineNo := 10000;
JobLedgEntry.SETRANGE("Job No.",SourceJobTask."Job No.");
JobLedgEntry.SETRANGE("Job Task No.",SourceJobTask."Job Task No.");
CASE TRUE OF
JobLedgerEntryType = JobLedgerEntryType::Usage:
JobLedgEntry.SETRANGE("Entry Type",JobLedgEntry."Entry Type"::Usage);
JobLedgerEntryType = JobLedgerEntryType::Sale:
JobLedgEntry.SETRANGE("Entry Type",JobLedgEntry."Entry Type"::Sale);
END;
JobLedgEntry.SETFILTER("Posting Date",SourceJobTask.GETFILTER("Planning Date Filter"));
IF JobLedgEntry.FINDSET THEN
REPEAT
TargetJobPlanningLine.INIT;
JobTransferLine.FromJobLedgEntryToPlanningLine(JobLedgEntry,TargetJobPlanningLine);
TargetJobPlanningLine."Job No." := TargetJobTask."Job No.";
TargetJobPlanningLine.VALIDATE("Line No.",NextPlanningLineNo);
TargetJobPlanningLine.INSERT(TRUE);
IF JobLedgEntry."Entry Type" = JobLedgEntry."Entry Type"::Usage THEN
TargetJobPlanningLine.VALIDATE("Line Type",TargetJobPlanningLine."Line Type"::Schedule)
ELSE BEGIN
TargetJobPlanningLine.VALIDATE("Line Type",TargetJobPlanningLine."Line Type"::Contract);
TargetJobPlanningLine.VALIDATE(Quantity,-JobLedgEntry.Quantity);
TargetJobPlanningLine.VALIDATE("Unit Cost (LCY)",JobLedgEntry."Unit Cost (LCY)");
TargetJobPlanningLine.VALIDATE("Unit Price (LCY)",JobLedgEntry."Unit Price (LCY)");
TargetJobPlanningLine.VALIDATE("Line Discount %",JobLedgEntry."Line Discount %");
END;
ExchangeJobPlanningLineAmounts(TargetJobPlanningLine,SourceJob."Currency Code");
IF NOT CopyQuantity THEN
TargetJobPlanningLine.VALIDATE(Quantity,0);
NextPlanningLineNo += 10000;
TargetJobPlanningLine.MODIFY;
UNTIL JobLedgEntry.NEXT = 0;
CopyJobPrices(SourceJob : Record Job;TargetJob : Record Job)
SourceJobItemPrice.SETRANGE("Job No.",SourceJob."No.");
SourceJobItemPrice.SETRANGE("Currency Code",SourceJob."Currency Code");
IF SourceJobItemPrice.FINDSET THEN
REPEAT
TargetJobItemPrice.TRANSFERFIELDS(SourceJobItemPrice,TRUE);
TargetJobItemPrice."Job No." := TargetJob."No.";
TargetJobItemPrice.INSERT(TRUE);
UNTIL SourceJobItemPrice.NEXT = 0;
SourceJobResourcePrice.SETRANGE("Job No.",SourceJob."No.");
SourceJobResourcePrice.SETRANGE("Currency Code",SourceJob."Currency Code");
IF SourceJobResourcePrice.FINDSET THEN
REPEAT
TargetJobResourcePrice.TRANSFERFIELDS(SourceJobResourcePrice,TRUE);
TargetJobResourcePrice."Job No." := TargetJob."No.";
TargetJobResourcePrice.INSERT(TRUE);
UNTIL SourceJobResourcePrice.NEXT = 0;
SourceJobGLAccountPrice.SETRANGE("Job No.",SourceJob."No.");
SourceJobGLAccountPrice.SETRANGE("Currency Code",SourceJob."Currency Code");
IF SourceJobGLAccountPrice.FINDSET THEN
REPEAT
TargetJobGLAccountPrice.TRANSFERFIELDS(SourceJobGLAccountPrice,TRUE);
TargetJobGLAccountPrice."Job No." := TargetJob."No.";
TargetJobGLAccountPrice.INSERT(TRUE);
UNTIL SourceJobGLAccountPrice.NEXT = 0;
CopyJobDimensions(SourceJob : Record Job;TargetJob : Record Job)
DefaultDimension.SETRANGE("Table ID",DATABASE::Job);
DefaultDimension.SETRANGE("No.",SourceJob."No.");
IF DefaultDimension.FINDSET THEN
REPEAT
WITH NewDefaultDimension DO BEGIN
INIT;
"Table ID" := DATABASE::Job;
"No." := TargetJob."No.";
"Dimension Code" := DefaultDimension."Dimension Code";
TRANSFERFIELDS(DefaultDimension,FALSE);
INSERT(TRUE);
END;
UNTIL DefaultDimension.NEXT = 0;
CopyJobTaskDimensions(SourceJobTask : Record "Job Task";TargetJobTask : Record "Job Task")
DimensionManagement.CopyJobTaskDimToJobTaskDim(SourceJobTask."Job No.",
SourceJobTask."Job Task No.",
TargetJobTask."Job No.",
TargetJobTask."Job Task No.");
ExchangeJobPlanningLineAmounts(VAR JobPlanningLine : Record "Job Planning Line";CurrencyCode : Code)
Job.GET(JobPlanningLine."Job No.");
IF CurrencyCode <> Job."Currency Code" THEN BEGIN
IF (CurrencyCode = '') AND (Job."Currency Code" <> '') THEN BEGIN
JobPlanningLine."Currency Code" := Job."Currency Code";
JobPlanningLine.UpdateCurrencyFactor;
Currency.GET(JobPlanningLine."Currency Code");
Currency.TESTFIELD("Unit-Amount Rounding Precision");
JobPlanningLine."Unit Cost" := ROUND(
CurrExchRate.ExchangeAmtLCYToFCY(
JobPlanningLine."Currency Date",JobPlanningLine."Currency Code",
JobPlanningLine."Unit Cost (LCY)",JobPlanningLine."Currency Factor"),
Currency."Unit-Amount Rounding Precision");
JobPlanningLine."Unit Price" := ROUND(
CurrExchRate.ExchangeAmtLCYToFCY(
JobPlanningLine."Currency Date",JobPlanningLine."Currency Code",
JobPlanningLine."Unit Price (LCY)",JobPlanningLine."Currency Factor"),
Currency."Unit-Amount Rounding Precision");
JobPlanningLine.VALIDATE("Currency Date");
END ELSE BEGIN
IF (CurrencyCode <> '') AND (Job."Currency Code" = '') THEN BEGIN
JobPlanningLine."Currency Code" := '';
JobPlanningLine."Currency Date" := 0D;
JobPlanningLine.UpdateCurrencyFactor;
JobPlanningLine."Unit Cost" := JobPlanningLine."Unit Cost (LCY)";
JobPlanningLine."Unit Price" := JobPlanningLine."Unit Price (LCY)";
JobPlanningLine.VALIDATE("Currency Date");
END ELSE BEGIN
IF (CurrencyCode <> '') AND (Job."Currency Code" <> '') THEN BEGIN
JobPlanningLine."Currency Code" := Job."Currency Code";
JobPlanningLine.UpdateCurrencyFactor;
Currency.GET(JobPlanningLine."Currency Code");
Currency.TESTFIELD("Unit-Amount Rounding Precision");
JobPlanningLine."Unit Cost" := ROUND(
CurrExchRate.ExchangeAmtFCYToFCY(
JobPlanningLine."Currency Date",CurrencyCode,
JobPlanningLine."Currency Code",JobPlanningLine."Unit Cost"),
Currency."Unit-Amount Rounding Precision");
JobPlanningLine."Unit Price" := ROUND(
CurrExchRate.ExchangeAmtFCYToFCY(
JobPlanningLine."Currency Date",CurrencyCode,
JobPlanningLine."Currency Code",JobPlanningLine."Unit Price"),
Currency."Unit-Amount Rounding Precision");
JobPlanningLine.VALIDATE("Currency Date");
END;
END;
END;
END;
SetCopyQuantity(CopyQuantity2 : Boolean)
CopyQuantity := CopyQuantity2;
SetCopyJobPlanningLineType(JobPlanningLineType2 : ' ,Schedule,Contract')
JobPlanningLineType := JobPlanningLineType2;
SetCopyOptions(CopyPrices2 : Boolean;CopyQuantity2 : Boolean;CopyDimensions2 : Boolean;JobPlanningLineSource2 : 'Job Planning Lines,Job Ledger Entries';JobPlanningLineType2 : ' ,Schedule,Contract';JobLedgerEntryType2 : ' ,Usage,Sale')
CopyPrices := CopyPrices2;
CopyQuantity := CopyQuantity2;
CopyDimensions := CopyDimensions2;
JobPlanningLineSource := JobPlanningLineSource2;
JobPlanningLineType := JobPlanningLineType2;
JobLedgerEntryType := JobLedgerEntryType2;
SetJobTaskRange(JobTaskRangeFrom2 : Code;JobTaskRangeTo2 : Code)
JobTaskRangeFrom := JobTaskRangeFrom2;
JobTaskRangeTo := JobTaskRangeTo2;
SetJobTaskDateRange(JobTaskDateRangeFrom2 : Date;JobTaskDateRangeTo2 : Date)
JobTaskDateRangeFrom := JobTaskDateRangeFrom2;
JobTaskDateRangeTo := JobTaskDateRangeTo2;
Did you perform any customization to Job tables? If you are using NAV 2013 you can turn on debugging to check the specific statement in error, probably in trigger Code of codeunit 1006 Copy Job.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156