Copy Job Error

nvermanverma Member Posts: 396
A functionality was added to the Job card, which allows the user to copy a job card, so they dont have to enter the information over and over again.

But, recently a user report, that the copy job function is not working, it throws an error: "The Job task already exists....Identification Fields and Values.. Job No = HV18701 Job Task No = 01.

I went to look for this Job Task No, it doesnt exists in the system (I made sure that no filters were on).

However, I noticed something very strange, it allows me to copy certain Jobs but not all of em. Any ideas what might be the issue.

Code to copy.
// Copy the job details from the source job to the new job
lrecNewJob.INIT;
lrecNewJob."Program" := CurrentJob."Program";
lrecNewJob.INSERT(TRUE);
lrecNewJob.TRANSFERFIELDS(CurrentJob,FALSE);
lrecNewJob.Status := lrecNewJob.Status::"Pre-Service";
lrecNewJob."Renewal Job No." := '';
lrecNewJob."Contract Renewal Date" := 0D;

// Set the Original Job No. to the passed job's number.
lrecNewJob."Original Job No." := CurrentJob."No.";
lrecNewJob.MODIFY;

// Copy the associated job tasks from the source job to the new job
JobTask.SETRANGE("Job No.", CurrentJob."No.");

IF JobTask.FIND('-') = TRUE THEN
REPEAT
  NewJobTask.INIT;
  NewJobTask.TRANSFERFIELDS(JobTask);
  NewJobTask."Job No." := lrecNewJob."No.";
  NewJobTask.INSERT;
UNTIL JobTask.NEXT = 0;

// Return the new job's number
EXIT(lrecNewJob."No.");

After doing a bit more snooping around, I found out that, if I am successfully at copying the job (a new job card is created with the same information...When I try to copy this new card, it throws the error message). Any idea how I can fix this.

Comments

  • DenSterDenSter Member Posts: 8,307
    Figuring things like this out is one of the things you need to learn how to do yourself. You can't just post code to the forum and expect others to figure it out for you. This looks like a very simple error to troubleshoot, and you just need to keep at it until you figure it out.

    Turn on the debugger, step through the code, keep track of values, compare those values against what you are expecting, figure out what is going wrong and fix it. Start again, until you solve the issue.

    Hint: it is trying to insert the same record more than once, so you need to figure out where that is going wrong. Use the values in the error message as clues and investigate.

    Good luck :mrgreen:
  • nvermanverma Member Posts: 396
    I have stepped through the code, a few times already and followed it through...and it gives me error on this last line: EXIT(lrecNewJob."No.")

    I wil keep trying to debug it :)
  • DenSterDenSter Member Posts: 8,307
    That error message is caused when you try to insert a record that already exists, and an EXIT statement does not insert anything. You have to READ the error message. Look at the job number HV18701 is that the new job's number or the one that you're copying from? Where does that number come from? Where is it supposed to go? What is going wrong there?

    I know exactly what the problem is just from looking at your code, you need to learn to figure it out. I really hope nobody steps in and tells you because I think this is a very important lesson for you to learn.
  • nvermanverma Member Posts: 396
    18701 is the new job no. that was created. The original job was 18020

    The (18701) no was assigned using a no. series.

    The issue is with the field: JOb Tasks No.
    Since we have copied it once, the Job Tasks No is 01, so when we try to copy it again the next time, the job task no. still stay at 01, rather then get incremented???
  • nvermanverma Member Posts: 396
    SOLVED!
      IF NewJobTask."Job Task No." = '' THEN
      BEGIN
          NewJobTask.INSERT
      END;
    

    Thanks Den, for pointing me in the right direction. :thumbsup:
  • DenSterDenSter Member Posts: 8,307
    No that's not it at all. All you are doing there is only inserting if the task number is blank. The value '01' came from the original job task, and you would want to copy that one over as well. The problem is that with your code it tries to insert the same record more than once, so you have to figure out WHERE IS IT GETTING THOSE VALUES???????

    What happens if the original job has more than one task, or if the original job has a task that has a value for the task number? You have to be able to loop through a set of data, copy that data and insert all of them with new key values.

    See this is the problem with you not having a senior. You don't have someone sitting next to you explaining how stuff works. You've been at this for months and still you are not making any meaningful progress, you are making the same mistakes over and over and it doesn't look like you understand basic concepts. Go to your boss and ask for senior support.
  • nvermanverma Member Posts: 396
    Job Task no. is set by a default field. Thats why its was conflicting before.

    Thats why i made it only add a task no. if its empty.
  • DenSterDenSter Member Posts: 8,307
    Nope still not it, but whatever, you keep it where it is, when your customer starts testing this they will call you and let you know where the problem is
  • nvermanverma Member Posts: 396
    The whole point of a form is to help people who do not have as much experience as you. I agree with one thing you say: "Give a man a fish, you feed him for a day. But teach a man to fish, you feed him a lifetime. I ask questions on the form, when I am stuck, I dont ask for the code. I just want to be pushed in the right direction.

    I know I aint no professional and I am still in the learning phase, but its not very nice to put someone down, just because they aint as skilled as you. I bet when you started off, you weren't as good aswell, but with time you learned things. But if every time you got stuck (when you were new), and someone rubbed it in ur face, that you are not good (you haven't learned anything) that's just a douche bag move (but what do i know, I am just a newbie)

    I aint here to start a fight or anything, just like you I am trying to make a living, so cut me some slack just caz i aint as knowledgeable as you.
  • DenSterDenSter Member Posts: 8,307
    nverma wrote:
    I bet when you started off, you weren't as good aswell, but with time you learned things.
    You're right. When I first started, I had a senior who was in my office that I could always ask questions. He would spend significant time with me to explain how things work. Not just syntax but troubleshooting skills. This senior was there for me for probably the first year of my career, and all of the other developers were always ready to lend a hand. Then after 3 months, my employer sent me to a two week training, where I did the NAV development training, and passed the exam at the end of that. I had proper support and training. When I kept making the same mistake, my senior never pretended that there was no problem. If I kept asking the same question he would get mad with me too. Instead of getting all offended because he would point out a mistake I would look at myself and maybe consider that there is something else to be learned.

    I'm not putting you down, but I'm not going to apologize for being direct with you. You were dismissing the idea that it is still not good, and I was calling you on it. I'm also identifying the fact that you seem to have no help from a senior, and no prper training, which is the biggest problem here. If you DID have a senior, if you DID get the proper training, you would be ten times the developer that you are now. The only thing you have is help from this forum, you're asking the wrong questions, you're getting really bad advice from some people, and as a result you are developing some REALLY bad habits.

    This should be addressed by your boss. Your employer should provide everything you need to succeed, and you're obviously not getting it. That's not your fault but it IS a problem.

    I've spent significant time trying to provide some guidance to you, and see if I could give you some sort of 'online senior' guidance. At first I thought I saw that you were really making some good progress, but I can clearly see the frustration building, so that proves yet again to me that this forum is NOT the right place for that type of help. It looks like you really just want people to tell you what the code should be instead. That's fine with me, but I'm not here to write your code for you.
  • nvermanverma Member Posts: 396
    You are right. I am taking it to heart, you are just trying to help me. The only way I will get better at this, if I had someone pointing me in the right direction and I have noticed that you had savage been doing a pretty good job of mentoring me and the rest of the form. At times I do get very annoyed if I cant figure something out and thats my fault and i shouldnt take it personally. I do appreciate all the help you have given me.

    I think I got the problem now. I just have to write a condition in my code to create a job task if no job task exists ( i think that might fix the issue).
  • DenSterDenSter Member Posts: 8,307
    The only thing you've done now is create a process without an error message, but the code that you have posted is still not properly copying the job and related tasks. You have to test and verify the results.

    Create a new job manually (make sure that you give it a description, assign a bill-to, enter an address, etcetera), and make sure that it has 2 or 3 tasks associated with it. You can also go through the list of existing jobs and select one that has multiple tasks. Then run the routine that you programmed for it. Verify that the new job has all the fields copied, and all of the tasks are also copied into the new job. When you have verified that the job (with all the field values) and tasks copy properly, then come back and tell us that it is solved.
  • nvermanverma Member Posts: 396
    Actually, you are right, it does not copy any of the job task info expect initalize the default one with the code i had before

    I gotta find a way around this.

    This simple little issue is starting to turn into such a big headache. ](*,) ](*,)

    @ Den - I wish I get to be as good as you one day. You just looked at the code and you told me the reason the code wont work. You got some major SKILLZZZ!! =D>
  • DenSterDenSter Member Posts: 8,307
    Do you know what 'primary key' means? Do you know what makes a key a primary key?
  • nvermanverma Member Posts: 396
    primary key: basically its a unique identity for each record. Its the first key in the keys menue. It is used to differenciate between two records.

    Thast all i remember.
  • nvermanverma Member Posts: 396
    Basically, this is what my manager told me and I need to write code to for this:
    "If the Program Setup contains default Job Task No. then don't even add the job tasks from the job to be copied.
    If the new job doesn't have a job task defined, only then do you copy the job task from the job to be copied
    If the new job contains job tasks (done through Program Setup), then you skip copying job tasks"

    Now I sorta, know where I am going.

    This is sorta off topic, how do you delete a message in a post??? Is that even possible?
  • DenSterDenSter Member Posts: 8,307
    Well that makes absolutely no sense at all. Of course the new job is not going to have a job task. It's a new job, so it doesn't have anything attached to it when it is created. You must be working in a database that has customizations in there.

    The reason why I am asking about primary key is because if you really understand that, you will also understand how filters on a compound primary key will affect what you need to take care of for a new job. The job task are related to the job by way of the job number, so when you copy a job task from one job to another, all you need to do in the new job task is use the new job number.

    Filter on the old job number, loop, copy the record and change the job number, insert.
  • nvermanverma Member Posts: 396
    You are right, there have been a lot of customization's done for this client.
    For Instance, when a user creates a job card, it will automatically fill it with a default information for job task (Thats why when a job a created it will have a default job task no., Cost Center Code, etc)

    From the requirements my manager told me to do: I wrote this code and I thought it should have worked, but its not working. I have tried debugging it 5-6 times, but debugger keeps on crashing.
    JobTask.SETRANGE("Job No.", CurrentJob."No.");
    IF JobTask.FIND('-') = TRUE THEN
    REPEAT
       ProgramSetup.GET(CurrentJob."Program");
       NewJobTask.SETRANGE("Job No.", JobTask."Job No.");
       IF NewJobTask."Job Task No." = ProgramSetup."Default Job Task No." THEN
         CLEAR(NewJobTask."Job Task No.")
       ELSE 
       begin
         NewJobTask.INIT;
         NewJobTask.TRANSFERFIELDS(JobTask);
         NewJobTask."Job No." := lrecNewJob."No.";
         NewJobTask.INSERT
       end;        
    UNTIL JobTask.NEXT = 0;
    

    Any idea what might be causing the debugger to crash. I am pretty sure there is a flaw in my logic somewhere.
  • DenSterDenSter Member Posts: 8,307
    I'm sorry, I can't help you there. There can be a bunch of things, and to troubleshoot that you really need to have direct access to the screen. This is where you would sit down with your senior and step through the code together and troubleshoot what you see.
  • nvermanverma Member Posts: 396
    Ok. :)

    Just one last question (I refuse to give you on this):
    According to my manager this is what needs to be done. I have read these lines like atleast 50 times, I just want to run by you what I understood and you can tell me if I am on the right path.

    1) "If the Program Setup contains default Job Task No. then don't even add the job tasks from the job to be copied. --> If ProgramSetup has a default Job Task No. assigned to it, then we should not copy any Job tasks

    2) If the new job doesn't have a job task defined, only then do you copy the job task from the job to be copied --> This will never be the case, since when we create a job, it will always has a default job tasks, so I dont have to copy anything since it will never be empty (doesnt have job task). I am not really sure about this point.

    3) If the new job contains job tasks (done through Program Setup), then you skip copying job tasks" --> This is basically the same thing as 1
  • DenSterDenSter Member Posts: 8,307
    If your manager gives you a requirement that you don't understand, you should not be asking ME to clarify. Go to the source and have them explain it, and explain it again, until you understand what they mean.
  • nvermanverma Member Posts: 396
    That actually makes senses...hehehe.... :mrgreen:
Sign In or Register to comment.