Category Archives: NAV2016

Search an entire NAV database with 10 lines of code

So a friend and I talked about how to search for data in NAV across all tables, and I said, I can do that in 10 lines of code 🙂

That’s a “Show Up or Shut Up” moment. So here goes:

Here presented in an older version of NAV, just to show that this works in most versions:

The idea is simple:
1. Loop through all tables
2. For each table, create a RecordRef
3. Loop through all records in the RecordRef
4. Do a text search with STRPOS inside the FORMAT(RecordRef) text string.

The secret here is that the FORMAT command, when used on a Record or a RecordRef returns a TAB separated string with all the fields from the record.

If you want case in-sensitive search, use LOWERCASE on the SearchValue and the output of the FORMAT command.

This is not fast, optimized or anything other that very complete and only 10 lines of code 🙂

PAGE.RUN Crash

I have just been battling a strange error. When I called a certain page in our solution all clients just crashed, hard.

So what was different with this page? It’s card page,  connected to a list page, works great when users double click on a record in the list page the card opens – Works perfectly.

But if I open the card page directly with PAGE.RUN(xxx,SomeRec) all clients crash!

In the stack trace, I could see something about subforms (DoBuildSubform) so I suspected the culprint was a pagepart (Yeah, Microsoft still calls it “forms” in their code) and I removed my subforms. Sure enough, now everything worked. I inserted each pagepart until I found the offending page.

The sub page uses the BusinessChart control, and it was the only control on that page. Running the sub page didn’t reviel anything strange, so I was puzzled for awhile …

Poking around, I suddenly notices that the PageType was a ListPart, with only one control on the page. There was really no listable thing to do, so I tried to change it into a CardPart instead – and sure enough, now everything worked 🙂

TL;DR Putting a control add-in on a ListPart subpage can crash all clients when the parent page is called with PAGE.RUN or PAGE.RUNMODAL – Change to CardPart to fix crash.

Type: System.ArgumentOutOfRangeException
Message: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
StackTrace:
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Microsoft.Dynamics.Nav.Client.FormBuilder.ActionBuilder.CreateOpenAndCreateAction(LogicalForm parentForm, ActionDefinition actionDef, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\ActionBuilder.cs:line 998
   at Microsoft.Dynamics.Nav.Client.FormBuilder.ActionBuilder.CreateMenuAction(ActionDefinition actionDef, LogicalControl parent, UIBuilderContext context, String& imageName) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\ActionBuilder.cs:line 377
   at Microsoft.Dynamics.Nav.Client.FormBuilder.ActionBuilder.CreateAction(ActionDefinition actionDef, LogicalControl parent, UIBuilderContext context, String& imageName) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\ActionBuilder.cs:line 115
   at Microsoft.Dynamics.Nav.Client.FormBuilder.ActionBuilder.DoBuild(ActionDefinition definition, LogicalControl parent, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\ActionBuilder.cs:line 1273
   at Microsoft.Dynamics.Nav.Client.FormBuilder.CommandBarBuilder.CreateActions(CommandBarDefinition definition, UIBuilderContext context, LogicalControl logicalControl) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\CommandBarBuilder.cs:line 247
   at Microsoft.Dynamics.Nav.Client.FormBuilder.CommandBarBuilder.DoBuild(CommandBarDefinition definition, LogicalControl parent, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\CommandBarBuilder.cs:line 72
   at Microsoft.Dynamics.Nav.Client.FormBuilder.UIPartBuilder.DoBuild(MasterPage definition, BindingManager bindingManager, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\UIPartBuilder.cs:line 162
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PageBuilder.Build(MasterPage definition, BindingManager bindingManager, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Framework\PageBuilder.cs:line 117
   at Microsoft.Dynamics.Nav.Client.FormBuilder.InfopartBuilderBase`1.CreatePart(TDefinition definition, FormHostControl infopart, UIBuilderContext partContext, Boolean filteringAllowed) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\InfopartBuilderBase.cs:line 103
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PageInfopartBuilder.CreatePagePart(InfopartPageDefinition infoPartDefinition, FormHostControl infopart, UIBuilderContext partContext, Boolean filteringAllowed) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\PageInfopartBuilder.cs:line 236
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PageInfopartBuilder.DoBuildPagePartCommon(InfopartPageDefinition definition, LogicalControl parent, UIBuilderContext context, BuildingUIPart type, Boolean filteringAllowed) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\PageInfopartBuilder.cs:line 169
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PageInfopartBuilder.DoBuildSubForm(InfopartPageDefinition definition, LogicalControl parent, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\PageInfopartBuilder.cs:line 121
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PlaceholderBuilder.BuildChildControls(ControlContainerPlaceHolder definition, LogicalControl parent, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\PlaceHolderBuilder.cs:line 58
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PlaceholderBuilder.DoBuild(ControlContainerPlaceHolder definition, LogicalControl parent, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\PlaceHolderBuilder.cs:line 44
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PageBuilder.BuildContent(ContentAreaDefinition contentArea, LogicalForm form, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Framework\PageBuilder.cs:line 1184
   at Microsoft.Dynamics.Nav.Client.FormBuilder.CardPageBuilder.DoBuild(MasterPage definition, BindingManager bindingManager, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Builders\CardPageBuilder.cs:line 49
   at Microsoft.Dynamics.Nav.Client.FormBuilder.PageBuilder.Build(MasterPage definition, BindingManager bindingManager, UIBuilderContext context) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\Framework\PageBuilder.cs:line 117
   at Microsoft.Dynamics.Nav.Client.FormBuilder.BuilderSession.CreateLogicalForm(MasterPage metadata, FormState formState) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.Builder\BuilderSession\BuilderSession.cs:line 328
   at Microsoft.Dynamics.Nav.Client.PageRunCallbackHandler.RunPage(FormRunRequest formRequest) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\PageRunCallbackHandler.cs:line 136
   at Microsoft.Dynamics.Nav.Client.ServiceConnection.ProcessServerResponse(Object response) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.ServiceConnection\ServiceConnection.cs:line 2082
   at Microsoft.Dynamics.Nav.Client.ServiceConnection.CallServer[T](BeginCallServerMethod beginCallServerMethod, EndCallServerMethod`1 endCallServerMethod) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.ServiceConnection\ServiceConnection.cs:line 2029
   at Microsoft.Dynamics.Nav.Client.ServiceConnectionBase.ValidateField(NavRecordState& state, NavDataSet recDataSet, Int32 controlId) in S:\Depot\NAV110\Platform\ClientServerShared\Prod.Types\ServiceConnection\ServiceConnectionBase.cs:line 421
   at Microsoft.Dynamics.Nav.Client.DataBinder.NstDataAccess.ValidateField(ValidationItem validationItem) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Databinder\NSTDataAccess.cs:line 602
   at Microsoft.Dynamics.Nav.Client.DataBinder.NavBindingManager.ValidateField(ValidationItem validationItem) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Databinder\NavBindingManager.cs:line 1541
   at Microsoft.Dynamics.Nav.Client.Validation.RowEntryValidateItem.ValidateItem(ValidationItem validationItem) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Validation\RowEntryValidateItem.cs:line 44
   at Microsoft.Dynamics.Nav.Client.Validation.ValidationHelper.ExecuteValidation(ValidationItem validationItem, String message) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Validation\ValidationHelper.cs:line 434
   at Microsoft.Dynamics.Nav.Client.Validation.ValidationHelper.ValidateItem(ValidationItem validationItem) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Validation\ValidationHelper.cs:line 406
   at Microsoft.Dynamics.Nav.Client.Validation.ValidationHelper.Validate(IValidationCaller validationCaller, ValidationItem validationItem) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Validation\ValidationHelper.cs:line 233
   at Microsoft.Dynamics.Nav.Client.DataBinder.NavBindingManager.Validate(IValidationCaller validationCaller, ValidationItem validationItem) in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Databinder\NavBindingManager.cs:line 1479
   at Microsoft.Dynamics.Nav.Client.Validation.FieldValidationRule.<ValidateValue>d__4.MoveNext() in S:\Depot\NAV110\Platform\Client\Shared\Prod.Client.UI\Validation\FieldValidationRule.cs:line 66
   at Microsoft.Dynamics.Framework.UI.ValidationRule.ValidateRuleCollection(ValidationResult result, IEnumerable`1 rules, Object value, IValidationCaller validationCaller) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Validation\ValidationRule.cs:line 89
   at Microsoft.Dynamics.Framework.UI.EditLogicalControl.ValidateHost(IValidationCaller validationCaller, ValidationResult validationResult) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Forms\EditLogicalControl.cs:line 783
   at Microsoft.Dynamics.Framework.UI.ValidationHolder.ValidateInternal(IValidationCaller validationCaller, ValidationResult validationResult) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Validation\ValidationHolder.cs:line 159
   at Microsoft.Dynamics.Framework.UI.ValidationHolder.PerformValidation(IValidationCaller validationCaller, ValidationResult validationResult) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Validation\ValidationHolder.cs:line 136
   at Microsoft.Dynamics.Framework.UI.ValidationHolder.Validate(ValidationResult validationResult) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Validation\ValidationHolder.cs:line 120
   at Microsoft.Dynamics.Framework.UI.EditLogicalControl.SetObjectValue(Object value) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Forms\EditLogicalControl.cs:line 436
   at Microsoft.Dynamics.Framework.UI.StringControl.TrySettingStringValue(String value) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Forms\StringControl.cs:line 186
   at Microsoft.Dynamics.Framework.UI.SaveValueInteraction.InvokeCore(SaveValueInteractionInput logicalInteractionInput) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Interactions\LogicalInteractions\SaveValueInteraction.cs:line 132
   at Microsoft.Dynamics.Framework.UI.InteractionInvoker.Invoke[T](String interactionName, Action`1 invokeMethod, T input) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Interactions\InteractionInvoker.cs:line 42
   at Microsoft.Dynamics.Framework.UI.LogicalInteraction`1.Invoke(T logicalInteractionInput) in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Interactions\LogicalInteraction.cs:line 40
   at Microsoft.Dynamics.Framework.UI.InteractionManager.<>c__DisplayClass8_0.<InvokeInteractions>b__3() in S:\Depot\NAV110\Platform\Client\Shared\Prod.ClientFwk\Interactions\InteractionManager.cs:line 125
Source: mscorlib

 

NAV2018 – The tenant ‘default’ is not accessible

Something weird happened on my local dev machine. I have a standard installation of NAV2018 installed, currently upgraded to CU2. Suddenly I’m swamped with messages about the default tenant is not accessible.

In C/Side:

In the Modern Development Environment:

The strange this is that if I restart the service tier I can download symbols once, but if I try to download them twice, I’ll get the above error the second time?

From the RTC:

Then I tried to use the PowerShell Sync-NAVTenant command:

And boom, this because I had deleted a table without syncing the database (I was working on an uplifting concept).

The solution:

Use the PowerShell Sync-NAVTenant command to fix the missing sync.

And now the database is back to normal 🙂