Create Job Task Lines with an Codeunit

Hi community,

hope u can help me. … So my Problem is that I have an Codeunit which Makes an (Order/Quote) to a Project, that works, but i want to Transfer the Sales Line into an JobTask and Later into the JobPlanning line, but first I want to create the JobTasks

for Example :

I have an Order/Quote which has an Ressource and some Items in its Lines and i want to convert the Order/quote into the Project, so the codeunit must Transfer these Lines at first into JobTask and later into JobPlanningLines

My Codeunit :

Unbenannt.JPG

So my Company says, when there is a Item in the Sales Line, the Codeunti must create an JobTaks with the Number ‘0998’, so dont wonder.

What have I done wrong ?

The Codeunit doesnt create a JobtaskLine [:(]

Thanks for Replies

Hi,

I don’t know why are doing it. I would still suggest if want to have a hardcoded value then use some fields in setup for same.

Now about your issue -

Start with line no 04 of Function (image 1) & do it in rest of function -
Replace SalesLine with SourceSalesLine in Your Image1.

  1. Why are you passing jobtask as a Var of TransferSalesLinesToProjectPlanLine Function when you are using it in that function. Either Remove it or Use it in the Function insted of Job Task.

Hope it make sense.

Regards,
Saurav Dhyani
saurav-nav.blogspot.com

Hello Saurav,

thanks for the Replie.

It stil doesn´t create any JobTasks

My Codeunit now :

Maybe is my function call wrong ? You can see it in my first Post.

Have you tried debugging it?

Please add a message inside Sourcesalesline.findset to check whether code is executing beyond or not.

Similarly check at other areas as well.

Please run the job task table and check whether records are inserted or not.

Hello Moritz,
Can you set Like SourceSalesLine.SETRANGE(“Document Type”,SourceSalesLine.“Document Type”::Order);
and see for results. i think it is not able to find any set, hope it will solve your problem…

Ok he doesnt find something in the sales lines, are my filters right ?

My Codeunit now :

The Functioncall was also wrong, now i call the function in an Report which has an Request Page and Prozessing only.

7633.Unbenannt.JPG

Why cant he find something in the salesLines ?

Please pass Document Type also as parameter
and set filters on salesline as

SalesLine.SETRANGE(“Document Type”,SalesHeader.“Document Type”);
SalesLine.SETRANGE(“Document No.”,SalesHeader.“No.”);

Also set document type filter on Salesheader in 1st line

Hi,
First -
Pass the whole Primary key for sales header as - Document Type(DocType) and Document No.(DocNo), as you can have Sales Order and Sales Invoice with Same No.

Then in Function get the SalesHeader, using SalesHeader.GET(DocType,DocNo);

The Problem in the code still is
Third & Fourth Line Should be -
SalesLine.SETRANGE(“Document Type”,Sales Header".“Document Type”);
SalesLine.SETRANGE(“Document No.”,Sales Header".“No.”);

Hey Moritz,

Just update your code as

SalesHeader.SETRANGE(“No.”,SalesHeaderNo);
IF SalesHeader.FINDFIRST THEN BEGIN //Add this
SalesLine.SETRANGE(“Document No.”,SalesHeaderNo); Here both are correct SalesHeaderNo or SalesHeader.“No.”

Remove this line
SalesLine.SETRANGE(“Document Type”,“SalesLine…Document Type”); //This code has no Impact Or else pass some Document type if It’s for Order/Invoice or anything.

Hello Guys,

was the site yesterday down ?

@Sarav Dhynai

I´m not authorizied to change the primary key in an standard Table,

@Mohana

I did your Suggestion, but now the problem is he doesnt know to which project the lines should append,

He creates two new lines which is right but he dont know to which project.

My Codeunit :

And the Table 1001 " Job Task"

How can I tell him that the newly created Lines belong to the newly created project ?

I Create the Project also in the Codeunit but in an other function.

Sry for late Replie

Yes, site was down yesterday.
Good progress :slight_smile:

You have to get the newly created project no. and pass it to this function and assign the project no. also while inserting job task lines.

[mention:716a4eabc27e405f9eb3919568dacf92:e9ed411860ed4f2ba0265705b8793d05] yes, regret that I some troubles with the database yesterday, so it was down 2-3 hours. But it’s up and runs faster than before. :slight_smile:

Hello,

sry for late replie, but I was on Holiday ;D

[mention:114ef12b5eb9466ea842f39c52ba7882:e9ed411860ed4f2ba0265705b8793d05]

So I passed it to my Codeunit, am I´m doing it right ?

Codeunit:

My Report :

I think what i´m doing wrong is, that the Report doesn´t know which Job “No” the newly created Job has.

So the Codeunit doesn´t get a right Job “No”.

Thanks for Replies :smiley:

Yes, you are right that report and codeunits doesn’t know the job no.
there is a field Job No. in sales line table, are you filling this field or not?
or you can add a job no. field in request page of report and based on the input you can pass it to codeunit

Hello ,

No i dont´t fill Job No. in the Sales Line Table and i tried youre other solution but its not working :frowning:

My Suggestion is :

In my other fuction where i fill the Job “Header” there i say that Job.No = 0 , but he don´t write the 0 rather he writes the ongoing project number but why ?

can i copy this value and write to the Job No. in the Job task table ?

The Function :

Thanks for Replies

So you are creating Job based on Sales Header information and you want to use same Job no. while creating tasks?
Where is this getjobdescription called?
if Job no. field is available in the sales header table then add the newly created job no. to sales header job no. field.

PS: please set filter on document type also while trying to find Sales Header.
Use Get function.

  1. Yes I create a Job based on Sales Header information

  2. This Function is called in my Request Page

Report “Sales Header to Job”:

  1. “Job No.” is not available in the Sales Header Table

  2. The Function “getJobDescription” is working but i must rename it :smiley: i should rather call it "CreateJobCard "

When i Insert a new Job he takes the Ongoing Project Number, how can I create JobTasks to this newly created JobNo.

Now he just creates a JobTask but not for the newly created Job in the function above

I hope now you have an overview

Greetings Moritz

I solved it now with a simple Solution

In My Function where i create my Job Card :

I need a new global Variable where i can save the value like this :

JobNo := Job.“No.”;

And then when I create my JobTaskLines in the other Function:

JobTask.“Job No.” := JobNo;

Sry for the long Thread and Thanks to all who helped me :smiley:

Have a great Weekend

Greetings Moritz

If all you need is to know which Job No. was created by the function, but just needs to know this in the object you are calling the function from, then you could just add it as a return value.

Then you would change this line: Job.INSERT(TRUE); to IF Job.INSERT(TRUE) THEN EXIT(Job.“no.”); and it would return the job no. created.