Replacing Field Values in Microsoft Dynamics NAV 2013

Have you ever had the need to replace some values from a list of values?  For example, you need to change the Postal/Zip Code for a number of your customers.  Most of the time you would need to write a codeunit or report to accomplish that or even have the customer update each entry by hand.  What if you needed to do the same with your vendors?  That would require either modifying the previous codeunit/report or possibly just creating a new object to handle this or again having the customer update each entry by hand. 

Here is another option – a Replace page that you can add to any page with just a few lines of code. 

Fig 1. Replace Page

Field Descriptions:

  • Selected Field – use the AssistEdit () or type the field name to select the field that you want to replace values from.
  • Find What – the value that you want to find and replace with a new value.
  • Replace With – the value you want to replace the original value with.


  • Match – you can either match the “Whole field” or “Any part of the field”.
  • Match Case – allows you to match only if the case matches exactly.
  • Replace Whole Field – allows you to replace the whole contents of the field with the new value.
  • Records in Data Set – this is an indicator as to how many records are in your current filtered dataset.

How to implement the page:

If you import the attached object text file and follow these steps you will be able to add this to almost any page (at least where it makes sense).  For this example I will be updating the Customer List (Page 22).

1. Import and compile the attached object “Replace NAV2013.txt”.

2. Design the Customer Page (21).

3. Add a global variable named Replace and point it to Page 50050 (or whatever you may have changed it to prior to import)

4. Create a new action.

5. Go to the OnAction trigger for your new action and add the following code …

6. Compile your object and you should be ready to use it.


How it works:

  • The function LoadDataSet simply loads the appropriate filtered dataset.
  • The SetValidations function is optional.  If you are going to run the Replace page from a page that needs to run validations then you add the SetValidations function.  There are 2 parameters – ModifyLevel determines whether the modify trigger is run for that update.  The FieldLevel parameter is used to enable the field OnValidate triggers to be run.  The Field Level parameter is for all fields.  There is no way (at this point) to determine which fields will run the OnValidate and which ones won’t.

Note:  When use this Replace page, keep in mind that the TIME and DATETIME fields are very sensitive from a matching perspective.  Even though the TIME may only appear to be HH:MM:SS on the page, there will probably be a millisecond component to the TIME as well.  So, to have the best luck, it would probably be best to copy the value of the cell that you want to replace and use that as the value in “Find What” field.  This is true with the DATETIME fields as well.


These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.

Replace NAV2013.txt

Comments (10)

Cancel reply

  1. B says:

    Where is the attachment?

  2. Kamil Sacek (Kine) says:

    Of course, this could be a risky function, because it allows you to replace values in non-editable fields. It means, user could go around the Editable=No property and change values in such a field… just want to mention this…

  3. RFO says:

    How can null values be replaced?

  4. Simon says:

    Really nice function. 🙂

    @RFO There are no null values in NAV, it's not allowed. To replace empty fields just use ''.

  5. Luís Marques says:

    Top man! Thanks

    PS: Why did Microsoft remove this? -.-'

  6. OttoChr says:

    Great concept, I like it alot.

    Ive tested this in NAV 2015

    I had to do some corrections in order for it to work properly for my purpose, which was for Sales Order List ( page 9305).

    Firstly, the GETFILTERS doesn't return the SourceTableView, which is "WHERE(Document Type=CONST(Order))", so a manual SETRANGE was applied before the LoadDataset function.

    Secondly, because I run on a danish version, the filters were not applied correctly because it formats fields names instead of captions.

    Also, filters on Options didn't get applied properly.

    I will list my changes here, so if anyone else runs into the same problems, it might help.

    I had to change the LOCAL_ApplyFilters function.

    Added an local variable 'intTemp' of type Integer.

    changed the following lines:

     Line No.(in txt document)           Before                                                          After      

     line 492                            "IF FilteredFldRef.NAME = Filters[ICount][1] THEN BEGIN"        "IF FilteredFldRef.CAPTION = Filters[ICount][1] THEN BEGIN"

     line 534                            "TempOption := FilteredFldRef.OPTIONSTRING;"                    "TempOption := FilteredFldRef.OPTIONCAPTION;"

    and the whole 'OPTION' case to:



                 TempOption := FilteredFldRef.OPTIONCAPTION;  //already listed above

                 OptionCount := 0;

                 FOR intTemp := 1 TO STRLEN(TempOption) DO BEGIN

                   IF TempOption[intTemp] = ',' THEN

                     OptionCount += 1;


                 FOR intTemp := 1 TO OptionCount+1 DO BEGIN

                   IF Filters[ICount][2] = SELECTSTR(intTemp,TempOption) THEN BEGIN

                     OptionNo := intTemp;

                     intTemp := OptionCount+1





    The reason for using a intTemp is because the ICount is a reference to which filter its trying to apply,

    and by using the same variable in the FOR loops, that connection is lost.

    Under the 'OPTION' case, the ICount in "IF Filters[ICount][2]" is wrongly being incremented by the FOR loop.

    I hope this made sense for you 🙂

  7. Alex says:

    I have implement your tool and works great when updating journals. The problem I'm facing now is that tool is updating all journals in all companies.

    Example: Have 3 journal (Jnl1, jnl2, jnl3) on 5 different companies.

    If I run the tool to update description field on Jnl1-Company1, it will apply the changes on all journals for all 5 companies.


    Any suggestions?

  8. Peter says:

    @Alex: And you are sure the DataPerCompany is not changed to No for the table? Or the OnModify() trigger isn't doing syncing with the other companies? Nothing in the tool indicates it should do anything outside the current company.

  9. asdf says:

    Be alarmed that if you have a rec – xrec comparisan within the OnModify Trigger xrec is alway equal rec.

  10. Ansari Seemab says:

    How do I update a single document of purchase invoice.

Skip to main content