Thursday, March 9, 2023

D365 Retain record position on grid refresh

Microsoft Dynamics 365 Finance
When refreshing the datasource of a grid, a common requirement is to retain the position of the selected record.
The datasource function refresh(true) was supposed to handle this, but does not always work. Also getPosition() and setPosition() will not provide this functionality.

One way to solve it is to use findRecord(Common _record). For this to work you will need to fetch the record from the database, as simply using the cursor() record will not suffice.

  MyTable myTableCursor = MyTable_ds.cursor();
  MyTable myTableLocal = MyTable::findRecId(myTableCursor.RecId);
  MyTable_ds.executeQuery();
  if(myTableLocal)
  {
  	MyTable_ds.findRecord(myTableLocal);
  }

Monday, March 6, 2023

Build and sync menu items greyed out

Microsoft Dynamics 365 Finance
Just encountered a situation where the D365 "Build models" and "Synchronize database" menu elements in VS were disabled.
Solution turned out to be very simple:
Close Visual Studio and restart IIS

Tuesday, May 31, 2022

Delete VS workspaces for other users

Occasionally a developer leaves a project without deleting their Visual Studio workspaces. It doesn't help to delete the machine and generate a new one with the same name - you will still get this error message when trying to map a local folder:
The working folder K:\AosService\PackagesLocalDirectory is already in use by the workspace [WORKSPACENAME];[Username] on computer [COMPUTERNAME].
If the username presented is not your own name, the workspace is owned by another developer. To view all TFS workspaces use this command in a Visual Studio command prompt:
tf workspaces /owner:*
You see the workspace mentioned in your error message - but how to delete it?
You will need to run the workspaces command with a different output to get the information you need:
tf workspaces /owner:* format:xml
You now get an xml containing all workspaces but with extended information. You will need to find the workspace in your error and note the ownerid value.
<Workspace computer="COMPNAME" islocal="true" name="COMPNAME" ownerdisp="Username" 
ownerid="8e414ake-d6e8-4d74-98c6-d3876cd2b259user.name@company.com"
ownertype="Microsoft.IdentityModel.Claims.ClaimsIdentity" owner="aydfh7b0-c3b6-6c25-b2c1-d1chn77fead1" owneruniq="aydfh7b0-c3b6-6c25-b2c1-d1chn77fead1"> <Comment /> <LastAccessDate>2021-11-23T14:07:24.157+00:00</LastAccessDate> <OwnerAliases> <string>8e414ake-d6e8-4d74-98c6-d3876cd2b259user.name@company.com</string> <string>user.name@company.com</string> <string>Username</string> </OwnerAliases> </Workspace> <Workspace computer="mgie10032-1" islocal="true" name="mgie10032-5" ownerdisp="Some Admin" ownerid="8e32gse-d6e1-4d13-98c8-d387694f48asome.admin@company.com" ownertype="Microsoft.IdentityModel.Claims.ClaimsIdentity" owner="353aa275-dff5-6b21-8662-d561d7876cda" owneruniq="353aa275-dff5-6b21-8662-d561d7876cda"> <Comment /> <Folders> <WorkingFolder local="C:UsersAdmin65c631f1f2SourceWorkspacesProjectname" item="$/Projectname/Trunk/Dev/Metadata" /> </Folders> <LastAccessDate>2021-09-21T06:36:00.58+00:00</LastAccessDate> <OwnerAliases> <string>88e32gse-d6e1-4d13-98c8-d387694f48asome.admin@company.com</string> <string>some.admin@company.com</string> <string>some.admin@company.com</string> </OwnerAliases> </Workspace>
Providing you have Administer workspaces permission you can delete the workspace using this command:
tf workspace /delete [WORKSPACE];[OWNERID] /collection:[COLLECTION]

Monday, May 2, 2022

AXUpdateInstaller FileIOPermission

Microsoft Dynamics 365 for Finance

Got an error while trying to install ISV package using command line:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

The reason was that I had downloaded the installation package from the web. Windows automatically blocks zip-files downloaded from web, so you need to unblock it.
Before you unzip your installation files, right click the zip file > properties >

Click 'Unblock' and apply to unblock the zip file. Then unzip and commence with installation.

Monday, March 28, 2022

D365 Browse OData entities with simple URL

Microsoft Dynamics 365 for Finance

If you quickly want to see entity records using OData, just add /data/[Public collection name] to the environment URL!
https://yourenvironment.dynamics.com/data/Customers

Sunday, March 20, 2022

D365 WHS app get current worker user id

Microsoft Dynamics 365 Warehouse Management app

When you want to get the current WHS session worker user id using x++.

#WHSRF public static WHSUserId getCurrentWHSUserId() { WhsrfPassthrough pass = controller.parmSessionState().parmPass(); WHSUserId userId; if (pass.exists(#UserId)) { userId = pass.lookup(#UserId); } }

Friday, March 11, 2022

Deploy error "Cannot edit a record in Batch job"

Microsoft Dynamics 365 for Operations & Financials

Encountered a problem when deploying an ISV the other day.
03/11/2022 10:29:31: Infolog diagnostic message: 'System Job should be scheduled to run within 7 day(s) of last execution time' on category 'Error'.
03/11/2022 10:29:31: Infolog diagnostic message: 'Recurrence validation failed' on category 'Error'.
03/11/2022 10:29:31: Infolog diagnostic message: 'Cannot edit a record in Batch job (BatchJob).
The corresponding AOS validation failed.' on category 'Error'.
03/11/2022 10:29:40: Application configuration sync failed. Microsoft.Dynamics.AX.Framework.Database.TableSyncException: Custom action threw exception(s), please investigate before synchronizing again: 'ErrorException:Cannot edit a record in Batch job (BatchJob).


I found a solution in the dynamics community:

Step 1 : Select * from classidtable where name = 'SysFeatureTranslationPopulationBatch'
Step 2 : Get the ID, and Run --> Select batchjobid from batch where classnumber = RecId
Step 3 : Get the batchjobid, and Run --> Select * from BATCHJOB where RECID = batchjobid
Step 4: Update Batchjob set enddatetime=getdate()-1 where recid = batchjob RecId