Rename Primary Key

Sankaran_BalasubramonianSankaran_Balasubramonian Member Posts: 20
Hi All,

I am trying to rename a primary key field of a table, and am running into problems. Please advice.

Scenario
I am currently working on the Default Navision Job Master table. (Jobs : 167). The client requires to auto generate the number series for the Job based on certain conditions. The conditions are
a. Job Type (Could Be Any Thing)
b. Job Level (Boolean corresponds to Parent - Child).

Please refer the Fig00101 below for more information on the field placings.


I have also created a separate table, where the Job Type - Job Level - Number Series combination would be captured. Please refer Fig00102.


Now based on the user input in these two fields, I would want to create a new number for the Job. Since Navision creates the number when the user presses F3, I would have to replace that number and show custom generated number in the field. I have written the following code to achieve that.
// Get - Set The Number Based On Job Type
IF "Job Type" = '' THEN
BEGIN
  ERROR('Please select a Job Type to proceed.');
  EXIT;
END
ELSE
BEGIN
  IF NVJobMstr.GET("Job Type") = TRUE THEN
  BEGIN
    // Check Which No. Series To Get
    IF "Is Child" = TRUE THEN
    BEGIN
      // Get The Next Number Using Child Number Series
      sDocNo := NoSeriesMgt.GetNextNo(NVJobMstr."Child No. Series",0D,TRUE);
    END
    ELSE
    BEGIN
      // Get The Next Number Using Child Number Series
      sDocNo := NoSeriesMgt.GetNextNo(NVJobMstr."Parent No. Series",0D,TRUE);
    END;
  END
  ELSE
  BEGIN
    ERROR('A Get operation on table NV Job Type Master failed accessing data.');
    EXIT;
  END;
END;

// Delete Old Record From Table
IF DELETE(TRUE) = FALSE THEN
BEGIN
  ERROR('A Delete operation on table Jobs failed accessing data.');
END;

// Insert New Data Into Table
"No." := sDocNo;
IF INSERT(TRUE) = FALSE THEN
BEGIN
  ERROR('An Insert operation on table Jobs failed accessing data.');
END;
  
// Reset The Current Record
RESET;

Problem
Everything works fine. But when I try to close the window, I get a warning message saying "Rename Record ?". Please refer Fig00103.


Throughout my code, I have not used the RENAME keyword. And I looked into MIBUSO forums from where I figured out that it is better to DELETE + INSERT than to RENAME.
http://www.mibuso.com/forum/viewtopic.php?f=14&t=16743&hilit=Rename+REcord

Please do let me know how to overcome this problem. Thanks in advance for all the help.
--
Thanks & Best Regards

Sankaran Balasubramonian

Comments

  • matttraxmatttrax Member Posts: 2,309
    I've gotten this before when I call the UPDATE function. Changing it to UPDATE(FALSE) fixes the issue.
  • kinekine Member Posts: 12,562
    In this case I will preffer way around like using "internal" numbers for real Job No. and the number series selected on some conditions you can store into new field or into search name field etc. Because the way how you are doing it will lead to this kind of problems. Or you can use some sort of "wizard" to crete the record, which will collect the info from the user first, and than it will create the record with correct no. series...(may be best way when I am thinking about it) ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    redesign the logic so that you use standard nav job series numbers and just have the other two fields as properties of the job. There is no need to do it the way you are going.

    take two steps back and start again.
    David Singleton
  • David_SingletonDavid_Singleton Member Posts: 5,479
    kine wrote:
    In this case I will preffer way around like using "internal" numbers for real Job No. and the number series selected on some conditions you can store into new field or into search name field etc.

    as usual, Kine was quicker.
    David Singleton
  • redesign the logic so that you use standard nav job series numbers and just have the other two fields as properties of the job. There is no need to do it the way you are going.

    take two steps back and start again.

    Hi David,

    Can you please explain more in detail. I am pretty new to NAV. I have been working in Dynamics GP for more than 5yrs, now slowly shifting over to NAV. It would be of great help if you can explain as to how I can create properties for job. Are we trying to create a new form or something like that, and then link that to the main job form. Please do explain.
    --
    Thanks & Best Regards

    Sankaran Balasubramonian
  • kine wrote:
    In this case I will preffer way around like using "internal" numbers for real Job No. and the number series selected on some conditions you can store into new field or into search name field etc.

    as usual, Kine was quicker.

    Hi Kine,

    The client has a lot of customizations done on the Job Module. So if I store if else where, I will have to extended this number across all those customizations. Please advice.
    --
    Thanks & Best Regards

    Sankaran Balasubramonian
Sign In or Register to comment.