Friday, August 26, 2016

AX 2012 Copy Data between companies

I had this requirement from one of the customers who had 45 legal entities in the system. They maintained a certain setups and data which was expected to be consistent across the different legal entities in the system. Obviously doing is consistently across all the legal entities was quite time consuming and tedious.

Below is one of the code block used to copy Data Interval from one company to another

    CompanyInfo         companyList;
    LedgerPeriodCode    periodCodesCopy, periodCodesPaste;
    DataAreaName        sourceDataArea;
    ;


    sourceDataArea = curext();

    while select companyList
    where companyList.DataArea != sourceDataArea
    {
        changeCompany( companyList.DataArea )
        {
                periodCodesPaste.clear();
                periodCodesCopy.clear();

                periodCodesCopy.company( sourceDataArea );
                while select periodCodesCopy
                {
                    select periodCodesPaste
                    where periodCodesPaste.Code == periodCodesCopy.Code;

                    if ( !periodCodesPaste )
                    {
                        ttsBegin;
                        periodCodesPaste.data ( periodCodesCopy.data() ) ;
                        periodCodesPaste.insert();                       
                        ttsCommit;
                    }
                }

            }   //change company

        }   //companylist

    info( "Period codes are copied" );

Friday, June 24, 2016

Sharepoint 2013 Restoring Master Page

Master pages are sensitive. If you happen to mess up with one you can get into a mess. I recently made a change to the master page and uploaded to realize that it had an error. The problem is i was no longer able to access my website.

The solution was to use powershell to upload a copy of the master file with the error fixed and a different file name, as changes to the master file in use are not allowed (as it cannot be deleted).

Step 1: Upload a master file with a new name. (note that the master file being used cannot be deleted)
WebURL = "http://XXX:100"
$SourcePath ="C:\temp\afz_seattle.master"

#Get the Web
$web = Get-SPWeb $WebURL
#Get the Target folder - Master page Gallery
$MasterPageList = $web.GetFolder("Master Page Gallery")
#Set the Target file for Master page
$TargetPath = $Web.Url + "/_catalogs/masterpage/afz_seattle.master"
#Get the Master page from local disk
$MasterPageFile = (Get-ChildItem $SourcePath).OpenRead()
 #upload master page using powershell
 $MasterPage = $MasterPageList.Files.Add($TargetPath,$MasterPageFile,$false)
 $web.Update()        

Step 2: Once the new master file is uploaded with a different name change the templates to point to this file (Instead of the one with error).
$web = Get-SPWeb http://XXX:100
$web.CustomMasterUrl = "/_catalogs/masterpage/afz_seattle.master"
$web.MasterUrl = "/_catalogs/masterpage/afz_seattle.master"
$web.Update()

Thursday, June 09, 2016

AX 2012 Deployment

Publish all the Reports using AX Shell

>Publish -AXReport -Reportname *

Publish all EP componenets using AX Shell

>Publish-AXWebComponent -AOTNodePathList "Web" -websiteurl "http://XXX:nnn"

 where http://XXX:nnn refers to AX website and port on sharepoint

Sunday, May 08, 2016

AX2012 Deleting a workflow instance

Had this strange issue where we found that the RECID got maxed out for certain tables in the systemsequences table. This caused the system to turn unusable and the logins into the system got disabled unless the NEXTVAL was correct set again using SQL.

On investigation and careful monitoring we found that the workflow engine has lots of instances where the workflow was in pending status. We realized that this was a developer issue where the business record was getting approved on the first work item approval on the attached workflow. As a result the user was able to post the data without completing the workflow.

Another issue we found was that there were multiple instances created for the same record this happened as the system dialog for workflow comments was not modal and went in the background and the user was able to submit twice.

Due to the above issues we landed in a situation where we have lots of workflow instance to get rid of and hence this post.

The workflow instance related tables are identified as follows
  • SysWorkflowInstanceTable
  • SysWorkflowTable
  • WorkflowQueueDocumentCommonFlds
  • WorkflowTrackingArgumentTable
  • WorkflowTrackingCommentTable
  • WorkflowTrackingStatusTable
  • WorkflowTrackingTable
  • WorkflowTrackingWorkItem
  • WorkflowWorkItemTable

I have already created a class to save some of the work

Wednesday, May 04, 2016

Truncate log without backup

So often in the non production environments we require the database logs to be truncated and the backup in these cases really does not matter.

As the truncate only option has been removed by Microsoft to avoid misuse of the command, there still is a workaround to shrink the transcation log without having to actually back it up.

The trick is to backup the log to a nul disk as shown below
BACKUP LOG MicrosoftDynamicsAX_model TO DISK='NUL:'
dbcc shrinkfile( MicrosoftDynamicsAX_model_log, 0 )
BACKUP LOG MicrosoftDynamicsAX TO DISK='NUL:'
dbcc shrinkfile( MicrosoftDynamicsAX_log, 0 )

Sunday, May 01, 2016

Failed to create a session; confirm that the user has the proper privileges to log on to Microsoft Dynamics

We started to get this message in the workflow one fine day.

On investigation it was realized that the issue was occurring for all the workflows which were directed to a particular user. The user has all the required permissions as well.

On further investigation it was found that for some reason the SID link between the active directory and the user info stored in AX was broken. When i tried to click the default company link on the user info i got the below message.


So i deleted the user, imported the user again from active directory and gave the same permissions back. Also established the user link with the employee record. Resumed the workflows and things were back on track.

Tuesday, April 26, 2016

RECID Maxed out

We have been struggling with this issue of the system sequences table is getting maxed out on the RECID for some tables. While the table that gets maxed out are random and without a pattern it mostly happens for table no 65482.

We also identified that this happens mostly when some user logs into the system. Which led to a conclusion that there is something at the user login stage that is causing the problem. We took some help from microsoft support desk and generated the trace file for the login steps.

 To generate the startup trace file follow the following steps : -
  1. Login to the application server where the AOS is installed. 
  2. Start the performance monitor  (start -> run -> perfmon ) and initiate the trace log
  3. Go to User Defined and new 
  4. Create the new trace using the AOSTRACE.XML template 
  5. Log in with a client and stop it
  1.  Each trace would be created and saved in a folder with an .etl extension
  2. Copy the trace file created and open the same in Microsoft Dynamics AX Trace Parser. (can be found on the product CD).
When the trace file was analyzed it was found that the system was trying to run the initialization checklist on startup. This was evident from the fact that there were records in the following tables with running status.

  1. Syssetuplog 
  2. Syssetuppartitionlog  

These records were deleted using the following scripts : -



Delete from Syssetuplog
Where description like ‘Running’


Delete from Syssetuppartitionlog
Where description like ‘Running’

Once the above records were deleted we emptied all the compilation log and libraries and did a fresh compile of the application. 
The following table was truncated in the model database to get rid of any previous logs
  • SYSXPPASSEMBLY
       The following folders were truncated in the AX server folders to delete the CIL libraries
  •  C:\Program Files\Microsoft Dynamics AX\60\Server\XXX\bin\XppIL


It is assumed that that the initialized checklist got initiated when the second AOS was installed on our server. The process followed to compile and load an environment with 2 AOS servers was as follows


  1. Stop All AOS
  2. Start one AOS and wait until it is Running
  3. Run AXBUILD on that AOS C:\Program Files\Microsoft Dynamics AX\60\Server\XXX\bin\AXBUILD.exe xppcompileall
  4. When Finished with compilation, Restart this AOS
  5. Log into a client and run a FULL CIL
  6. When finished, stop the client, Stop the AOS
  7. Start the second AOS and wait until it is up running
  8. Start the First AOS
  9. Log in users
We also noticed an event viewer log suggesting a missing stored procedure in AX.
Run AXUTIL SCHEMA 
Run AXUTIL OPTIMIZE to rebuild the model database


Another possible reason that was potentially considered for the max out was that maybe due to internal procedures using the SystemSequences Table it is possible the locks are being escalated and the table is getting locked out. When AX is trying to read the locked table it is possible generating a higher no to avoid a duplicate.

ALTER TABLE SYSTEMSEQUENCES

SET (LOCK_ESCALATION = DISABLE);