Replacing Field Values in Microsoft Dynamics NAV 2013

Replacing Field Values in Microsoft Dynamics NAV 2013

Rate This
  • Comments 5

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.

Options:

  • 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.

Attachment: Replace NAV2013.txt
Leave a Comment
  • Please add 2 and 8 and type the answer here:
  • Post
  • Where is the attachment?

  • 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...

  • How can null values be replaced?

  • Really nice function. :)

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

  • Top man! Thanks

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

Page 1 of 1 (5 items)