Thursday, August 11, 2011

Check if record has been changed

there are times when you want to check if a table has been touched
before you do a process such as a refresh. here is code that can be
placed in a table to check whether any data in the record set has been
changed


boolean hasChanged()
{
SysDictTable sysDictTable;
int f;
fieldId fieldId;
;

sysDictTable = new SysDictTable(this.TableId);

for (f = 1; f <= sysDictTable.fieldCnt(); f++)
{
fieldId = sysDictTable.fieldCnt2Id(f);

if (this.orig().(fieldId) != this.(fieldId))
return true;
}
return false;
}

Monday, July 25, 2011

Basics of setting up AX2009 security keys

Set up alerts
a. Go to Basic > Number Sequence > Reference > System ID
i. Ensure that the Basic_01 number sequence exists. If not, create.
b. Set up Basic > Setup > Email Templates
c. Basic > Setup > Alerts > Set up email ID
d. Administration > Batch Groups
i. Create "Alerts" Batch Group
e. Administration > Setup > Server Configuration
i. Tick Is Batch Server
ii. On Batch server groups tab, select "Alerts"
f. Basic > Setup > Alerts > Manage alert rules
g. Basic > Setup > Alerts > Periodic > Alerts > Change based alerts
i. Add to "Alerts" batch group and send to batch
h. Basic > Setup > Alerts > Periodic > Alerts > Due date alerts
i. Add to "Alerts" batch group and send to batch
i. Administration > Common forms > Users > User options
i. Set up email
ii. On Notifications tab, set up parameters
iii. On Status Bar tab ensure the "Show alert status" is ticked
j. Set up security keys
i. http://technet.microsoft.com/en-us/library/aa834418(AX.50).aspx

Sunday, July 10, 2011

Manually upgrade Date and Time fields

after an AX2009 upgrade, if you happen to forget to upgrade a Date and
Time field combination on a table to the new DateTime field, use this
simple job.

in the case below, SysDatabaseLog's CreatedTime did not seem to be
upgraded to be incorporated into the new CreatedDateTime field.

=======

static void AX2009Upgrade_ManuallyUpgradeDateTime(Args _args)
{
DEL_SysUpgradeTimeZone listOfColumnsToBeUpgraded;
ReleaseUpdateDB_TimezoneUpgrade timezoneUpgradeClass;
;

ReleaseUpdateDB41_Basic::upgradeToDateTime
(
tablenum(SysDatabaseLog),

fieldnum(SysDatabaseLog, CreatedDateTime),

fieldnum(SysDatabaseLog, CreatedDateTime),

fieldnum(SysDatabaseLog, DEL_CreatedTime)
);

while
select
listOfColumnsToBeUpgraded
order by
listOfColumnsToBeUpgraded.RefTableId
where
listOfColumnsToBeUpgraded.Status == SysUpgradeTimeZoneStatusEnum::Ready
{
timezoneUpgradeClass =
ReleaseUpdateDB_TimezoneUpgrade::construct(
listOfColumnsToBeUpgraded.data() );
timezoneUpgradeClass.run();
}
pause;
}

Monday, June 6, 2011

How to recover database from MDF in SQL Server without an LDF

because there are times when you need to do something dodgy to save the day.

1. Detach database and move your mdf to save location.
2. Create new database of same name, same files, same file location
and same file size.
3. Stop SQL server.
4. Swap mdf file of just created DB to your save one.
5. Start SQL. DB will go suspect.
6. ALTER DATABASE yourdb SET EMERGENCY
7. ALTER DATABASE yourdb SET SINGLE_USER
8. DBCC CHECKDB (yourdb, REPAIR_ALLOW_DATA_LOSS)
9. ALTER DATABASE yourdb SET MULTI_USER
10. ALTER DATABASE yourdb SET ONLINE

source: http://stackoverflow.com/questions/773059/how-to-recover-database-from-mdf-in-sql-server-2005

Sunday, February 13, 2011

Wrong argument types for comparison

this is not the first time this piece of code has helped me to get rid
of a weird error:

ERROR:
Error executing code: Wrong argument types for comparison.

Stack trace:
(C) \Classes\QueryRun\next
(C) \Classes\FormDataSource\executeQuery
(C) \Forms\MyForm\Data Sources\MyFormDatasource\Methods\executeQuery - line 4
(C) \Classes\FormDataSource\linkActive
(C) \Forms\MyForm\Data Sources\MyFormDatasource\Methods\linkActive - line 3


SOLUTION:
on the form init,

public void init()
{
super();
this.query().dataSourceNo(1).clearDynalinks();
}

Wednesday, February 9, 2011

Counting how long a job takes

use this code to keep track of how long a piece of code takes to execute

timeofday starttime = timenow();
;
//your cool code here

info(strfmt("Total time taken: %1", time2StrHMS(timenow() - starttime)));