Fetch number of records in a FormDataSource (e.g. of a Grid)

SysQuery::getTotal works fine, but the trick is how to handle temporary data sources where getTotal does not work:

if(!formDataSource.curser().isTmp())
{
    recordCount = SysQuery::getTotal(formDataSource.queryRun());
}
else
{
    while(!formDataSource.allRowsLoaded())
    {
        formDataSource.getNext();
    }
    recordCount = formDataSource.numberOfRowsLoaded();
}

Now recordCount contains the number of Records in the FormDataSource irrespective of the Tmp status of the data source. Of course the whole tmp-data source has been loaded in the process, which might be an issue in some cases.

Advertisements

SQL Script: After Restore from PROD to TEST

Do you want PROD data in your TEST System? Easy, just restore a backup of PROD into your TEST-DB. Run the following script to clean up some AOS specific data:

Update [AX09_TEST].[dbo].[BatchServerGroup] set SERVERID = ’01@SRVAOS1′  where SERVERID = ’02@SRVAOS1′
–01: DEV, 02: PROD, 03: MIG

Update [AX09_TEST].[dbo].[BATCHSERVERCONFIG] set SERVERID = ’01@SRVAOS1′  where SERVERID = ’02@SRVAOS1′
–01: DEV, 02: PROD, 03: MIG

Update [AX09_TEST].[dbo].[SYSSERVERCONFIG] set SERVERID = ’01@SRVAOS1′ , SERVERGUID = newid() where SERVERID = ’02@SRVAOS1′
–01: DEV, 02: PROD, 03: MIG

Update [AX09_TEST].[dbo].[Batch] set SERVERID = ’01@SRVAOS1′  where SERVERID = ’02@SRVAOS1′
–01: DEV, 02: PROD, 03: MIG

delete [AX09_TEST].[dbo].[SYSCLIENTSESSIONS]

–the following has nothing to do with the restore to TEST
–remove obsolete [SYSCLIENTSESSIONS] from PROD

select * from [AX09_LIVE].[dbo].[SYSCLIENTSESSIONS] where STATUS = 0

delete [AX09_LIVE].[dbo].[SYSCLIENTSESSIONS] where STATUS = 0

Report Print Preview: “Go to main table” link for display method fields

Situation:
A report containing e.g. PurchParmLine.itemId() will not show the orange hyperlink in the print preview screen that allows the user to jump to the main table.

Solution:
To make add a link to a display method field on a report you must replace the display method field by a temporary table datasource. Populate the desired field and send the temporary datasource.

public void executeSection //e.g. located in PurchParmLine body
{
InventTable tmpPrintItemId; //any table with the ItemId field will do
    ;
tmpPrintItemId.ItemId = PurchParmLine.itemId();
element.send(tmPrintItemId);
super();
}

Now you can add a Field with Properties Table = Inventtable and DataField = ItemId, which will print the contents of PurchParmLine.itemId() and will have the orange hyperlink in the print preview that allows the user to jump to the main table.

See also msdn How to

Powershell script: Copy DEV Layers to LIVE

The following Powershell script copies the AX2009 DEV Layers to LIVE thereby checking that the services have been stopped and also copying the previous layers into old and backing up old in subfolders of old:

[void][System.Reflection.Assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
$AXSERVER_DEV = "srvaos2"
$AXSERVICE_DEV = "AOS50?01" # ? stands for $
$AXPATH_DEV = "\\"+ $AXSERVER_DEV + "\c$\Program Files\Microsoft Dynamics AX\50\Application\Appl\AX09_DEV"
$AXPATH_DEV_OLD = "\\"+ $AXSERVER_DEV + "\c$\Program Files\Microsoft Dynamics AX\50\Application\Appl\AX09_DEV\old"
$AXSERVER_PROD = "srvaos1"
$AXSERVICE_PROD = "AOS50?02" # ? stands for $
$AXPATH_PROD = "\\"+ $AXSERVER_PROD + "\c$\Program Files\Microsoft Dynamics AX\50\Application\Appl\AX09_LIVE"
$AXPATH_PROD_OLD = "\\"+ $AXSERVER_PROD + "\c$\Program Files\Microsoft Dynamics AX\50\Application\Appl\AX09_LIVE\old"
$LABELFILES = "axsa*.ald"
$LAYERFILES = "axcus*.aod"
$AOIFILES = "*.aoi"
$ALIFILES = "*.ali"
function copyAXAppl
{
#DEV and PROD services must be stopped	
	echo ("checking service " + $AXSERVICE_DEV + " on " + $AXSERVER_DEV)
	if((get-service -ComputerName $AXSERVER_DEV -name $AXSERVICE_DEV).status -eq "Stopped")
	{
		echo "ok" ("checking service " + $AXSERVICE_PROD + " on " + $AXSERVER_PROD) 
		if((get-service -ComputerName $AXSERVER_PROD -name $AXSERVICE_PROD).status -eq "Stopped")
		{
			echo "ok" ("copying from " + $AXPATH_DEV + " to " + $AXPATH_PROD)
#CREATE PROD\OLD BACKUP DIR (YYYYMMDD)
			if(-not (test-path (join-path $AXPATH_PROD_OLD (get-date -uformat "%Y%m%d"))))
			{
				new-item -path $AXPATH_PROD_OLD -name (get-date -uformat "%Y%m%d") -itemtype directory
			}			
#BACKUP PROD (only CUS Files)
			(dir -path $AXPATH_PROD -name $LABELFILES ) |
				foreach-object {copy $_.pspath (join-path $AXPATH_PROD_OLD (get-date -uformat "%Y%m%d")) }
			(dir -path $AXPATH_PROD -name $LAYERFILES) |
				foreach-object {copy $_.pspath (join-path $AXPATH_PROD_OLD (get-date -uformat "%Y%m%d")) }
#COPY PROD\OLD\{14 days old} -> PROD\OLD
			if(test-path (join-path $AXPATH_PROD_OLD (get-date (get-date).addDays(-14) -uformat "%Y%m%d")))
			{
				(dir -path (join-path $AXPATH_PROD_OLD (get-date (get-date).addDays(-14) -uformat "%Y%m%d")) -name "*.ald" ) |
					foreach-object {copy $_.pspath $AXPATH_PROD_OLD }
				(dir -path (join-path $AXPATH_PROD_OLD (get-date (get-date).addDays(-14) -uformat "%Y%m%d")) -name "*.aod" ) |
					foreach-object {copy $_.pspath $AXPATH_PROD_OLD }
			}
#CREATE DEV\OLD BACKUP DIR (YYYYMMDD)
			if(-not (test-path (join-path $AXPATH_DEV_OLD (get-date -uformat "%Y%m%d"))))
			{
				new-item -path $AXPATH_DEV_OLD -name (get-date -uformat "%Y%m%d") -itemtype directory
			}			
#BACKUP DEV (only CUS Files)
			(dir -path $AXPATH_DEV -name $LABELFILES ) |
				foreach-object {copy $_.pspath (join-path $AXPATH_DEV_OLD (get-date -uformat "%Y%m%d")) }
			(dir -path $AXPATH_DEV -name $LAYERFILES) |
				foreach-object {copy $_.pspath (join-path $AXPATH_DEV_OLD (get-date -uformat "%Y%m%d")) }
#COPY DEV -> DEVOLD
			(dir -path $AXPATH_DEV -name "*.ald" ) |
				foreach-object {copy $_.pspath $AXPATH_DEV_OLD }
			(dir -path $AXPATH_DEV -name "*.aod" ) |
				foreach-object {copy $_.pspath $AXPATH_DEV_OLD }

#COPY DEV->PROD (only CUS Files)
			(dir -path $AXPATH_DEV -name $LABELFILES ) |
				foreach-object {copy $_.pspath $AXPATH_PROD }
			(dir -path $AXPATH_DEV -name $LAYERFILES ) |
				foreach-object {copy $_.pspath $AXPATH_PROD }
#DELETE PROD AOI
			(dir -path $AXPATH_PROD -name $AOIFILES ) |
				foreach-object {remove-item $_.pspath}
#DELETE DEV AOI
			(dir -path $AXPATH_DEV -name $AOIFILES ) |
				foreach-object {remove-item $_.pspath}
#DELETE PROD ALI
			(dir -path $AXPATH_PROD -name $ALIFILES ) |
				foreach-object {remove-item $_.pspath}
#DELETE DEV ALI
			(dir -path $AXPATH_DEV -name $ALIFILES ) |
				foreach-object {remove-item $_.pspath}
		}
		else
		{
			[System.Windows.Forms.MessageBox]::Show("First stop '" + (get-service -name AOS50?02).Displayname + "'")
		}
	}
	else
	{
		[System.Windows.Forms.MessageBox]::Show("First stop '" + (get-service -name AOS50?01).Displayname + "'")
	}
}

Edit 20.06.2014: variable servers