Monday, September 30, 2013

KeyReplacement

static void Job1(Args _args)
{
    VendTable vendTable;
    DirPartyTable dirpartyTable;
    int myCount;
    DirPartyPostalAddressView   addressView;
    DirPartyLocation dirpartyLocation;
    str 100 strStreet;
    LogisticsLocation logisticsLocation;
    LogisticsPostalAddress logisticsPostalAddress;
    RecId   recID;

    /*
    while select forupdate * from dirPartyTable
        where dirpartyTable.Name == 'Admin UnemploymentCompensation'
    {
        myCount++;
    }
    info(strFmt("%1", myCount));

    changeCompany('LOG')
    {
    strStreet = 'State of Connecticut; Dept. of Labor # 4713 PO Box 2905';
    select * from addressView
       where addressView.Street == strLRTrim(strStreet);
    info(strFmt("%1", addressView.RecId));
    }
      */
changeCompany('VER')
    {
        //Admin UnemploymentCompensation
        while select forupdate * from dirPartyTable
            where dirpartyTable.Name == 'Admin UnemploymentCompensation'
        {
            if(dirpartyTable.RecId)
            {
               while select forupdate dirpartyLocation
                    where dirpartyLocation.Party == dirpartyTable.RecId
               {
                   
                   logisticsLocation = LogisticsLocation::find(dirpartyLocation.Location, true);
                   logisticsPostalAddress = LogisticsPostalAddress::findByLocation(logisticsLocation.RecId, true);
                     
                    ttsBegin;
                    logisticsPostalAddress.doDelete();
                    logisticsLocation.doDelete();
                    dirpartyLocation.doDelete();
                 
                    ttsCommit;
                 
               }
               
               select forupdate * from vendTable
               where vendTable.Party == dirpartyTable.RecId;
                if(vendTable.RecId)
                {
                    ttsBegin;
                    vendTable.doDelete();
                    dirpartyTable.delete();

                    ttsCommit;
                }
               
            }
        }

    }


}

TempTable

static void CopyPersistedTableToInMemoryJob(Args _args)
{
    CustTable custTable;
    CustTable custTmpLedger;

    custTmpLedger.setTmp();
    custTable.recordLevelSecurity(true);

    while select * from custTable where custTable.AccountNum like '1*'
    {
        custTmpLedger.data(custTable.data());
        custTmpLedger.doInsert();
        info(strFmt("Inserted a row for AccountNum = %1",custTable.AccountNum));
    }

    custTmpLedger = null;
}
The code copies data from the CustTable into an InMemory table. 
The setTmp method is used to create the same structure as it is on the physical table. The method changes the value from TableType::regualar to TableType::InMemory. A TempDB table is instantiated in the underlying database management system when the first SQL operation is sent to the database system from the AOS. The SQL operation can be either select, insert, update, or delete.
Variable goes out of scope. The typical case is that a method declares a variable for the particular TempDB type. The method inserts data into the TempDB table. The insert causes the table to be instantiated in the database. When the method finishes, all variables declared in the method go out of scope. The AOS tells the database system to drop the TempDB table when its corresponding variable does out of scope.

Create a TestTmp as InMemory table with Id a string type as a field.
static void TestTmpInMemory(Args _args)

{

    TestTmp tmp1, tmp2;
    ;

    tmp1.Id = "1000";
    tmp1.insert();

    tmp2.setTmpData(tmp1);

    info("Tabletype: " + enum2Str(tmp1.getTableType()));
   
    info("tmp1data begin: ");

    while
        select tmp1
            info("    Id " + tmp1.ID);


    info("tmp1data end.");

    info("tmp2 data begin: ");

    while
        select tmp2
            info("    Id " + tmp2.ID);

    info("tmp2 data end.");

}

Thursday, September 26, 2013

Insert and Delete

 LOGISTICSADDRESSCOUNTRYREGIONTRANSLATION country;

    select forupdate country where country.LanguageId == 'en-us';
    country.CountryRegionId = 'Canada';
    country.ShortName = 'Canada';
    country.LongName = 'Canada';
    country.insert();
   
    ttsBegin;
    while select forupdate country where country.LanguageId == 'en-us' && country.CountryRegionId == 'Canada'
    {
        country.delete();
    }
    ttsCommit;

   

Wednesday, September 25, 2013

Run a Query

static void Job3(Args _args)
{
    Query       q;
    QueryRun    qr;

    VendTable   vendTable;
    LogisticsLocation logisticsLocation;
    LogisticsPostalAddress postalAddress;


    q = new Query(queryStr(VendTableListPagePreviewPane));
    qr = new QueryRun(q);
    while (qr.next())
    {
        vendTable = qr.get(tableNum(VendTable));
        logisticsLocation = qr.get(tableNum(LogisticsLocation));
        postalAddress = qr.get(tableNum(LogisticsPostalAddress));

        info(strFmt("Account: %1, location; %2, County: %3", VendTable.AccountNum,
            logisticsLocation.LocationId,
            postalAddress.County));
    }
}

Apply Style


DEV and TEST

        On Dev
1.       Each team must use separate code prefix, label file and model:
a. All objects (except label file) must belong to model.
b. If development is going on DEV server - CUS layer must be used and
c. All changes must be checked in to MorphX VSS.
d. For development on other environments, please, use VAR layer.

To Test
                a. Delivery into TEST will be done by models.
                b. Delivery will be done during maintenance windows, so plan your work accordingly.
                c. Direct changes in TEST CUS layer are prohibited. If you need to apply quick fix/change you can do it in USR layer and move it to DEV. USR layer on TEST will be deleted on next deployment.
                d. If you are ready to move code to TEST:
- check that all objects are included in your model;
- check that code in model compiles without errors;
- notify my team. If you are ready with some piece, but you need to continue – please, export your model and label file in separate folder – and notify my team (same for external development).

Edit a page 

HTTP:\\MYSHAREPOINT?ToolPaneView=2&pagemode=edit

Tuesday, September 24, 2013

Args

static void OpenFormFunction()

Object formRun;
Args args = new Args();
;
args.name(formstr(CustTable));
args.record(CustTable::find('ABC'));

formRun = ClassFactory.formRunClass(args);
formRun.init();

formRun.yourmethodgoeshere(); /* !!

formRun.run();
formRun.wait();
}

Saturday, September 14, 2013

AXModel

What is the difference between MenuItem types - Display, Action and Output
output normally run reports
action normally run classes
display normally run forms


PS C:\>Export-AXModel -model Packaging -file c:\models\Packaging.axmodel

This example installs the MyModel file into the same layer that it was exported from.
Any conflicts will be pushed to the related update layer.
PS C:\>Install-AXModel -File MyModel.axmodel -Conflict Push

http://technet.microsoft.com/EN-US/library/hh352314.aspx

Friday, September 13, 2013

DAX Cue

Create a table, then a query, next create a menuitem. The menu item will use the Query, if not a form involved, in the objectType, it's Query, Object: [QueryName]; if it has form, it's Form and FormName.
Lastly, create a cue, put the label name and MenuItemName.

When all's done, Cue can be added from the Form and EP.

To Create the Menu Item

  1. In the AOT, expand Menu Items, right-click Display, and then click New Menu Item.
  2. Click the new menu item. In the property sheet, click Name and specify a name that uniquely identifies the menu item.
  3. Click Label and select the label for the menu item. The menu item label appears in the FactBox when the Label property of the cue is empty.
  4. Click Query and then click the name of the query that you want to use to retrieve the data records.
  5. Click ObjectType and select Form.
  6. Click Object and then click the name of the form that you use to show the records from the query. If you do not want to open a form from the cue, you can leave the property empty.
  7. If the cue appears in Enterprise Portal, click WebMenuItemName and select a WebMenuItem. Use a WebMenuItem that opens a list page that can display the set of records that the cue retrieved.
  8. Right-click the menu item and then click Save.

To Create the Cue

  1. In the AOT, expand Parts, right-click Cues, and then click New Cue. A cue is added to the list of Cues in the AOT.
  2. Click the new cue. In the property sheet, click Name and specify a name that uniquely identifies the cue.
  3. Click Label and select the label you want to appear in a FactBox. This step is optional. If the label is not specified, the cue uses the label from the menu item.
  4. Click MenuItemName and select the menu item that you created for the cue. This menu item specifies the query you want to use, as well as the form (for the Microsoft Dynamics AX client) or list page (for EP) that will be opened when the cue is clicked.
  5. Right-click the cue and then click Save.

Remove Duplicates

--select * from LOGISTICSADDRESSZIPCODE where ZIPCODE = '92620'

create table #TempRECID (myRecID bigint)

insert into #TempRECID (myRecID)
select A.RECID
from LOGISTICSADDRESSZIPCODE A
inner join LOGISTICSADDRESSZIPCODE B
on A.ZIPCODE = B.ZIPCODE
and A.COUNTY<>B.COUNTY
and B.COUNTY <> ''
--and B.ZIPCODE = '92620'

--select * from #TempRECID

delete AA from LOGISTICSADDRESSZIPCODE AA
inner join #TempRECID B on AA.RECID = B.myRecID
--where RECID = '5637148309'

drop table #TempRECID

--select * from LOGISTICSADDRESSZIPCODE where RECID =  '5637148309'

===========================================================
update dbo.LOGISTICSADDRESSZIPCODE
set ZIPCODE = '0' + ZIPCODE
where len(zipcode) = 4

Thursday, September 12, 2013

Master Page and Logo

In dynamics ax 2012, you can change the logo from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ep\images\ location and change the name you your logo file to DynamicsLogo64x64.png

Dynamics AX 2009 Enterprise Portal was designed with templates compatible with SharePoint 2007, and they are in this compatible mode in SharePoint 2010. Hence not all features are compatible for example with SharePoint Designer. Hence you are unable to edit the master page using this tool. Even if you could edit the master page using the SharePoint Designer, every time you update Enterprise Portal, say using AXUPDATEPORTAL.EXE, it would override the default master page with the copy stored in the AOT.
So therefore to edit the master page do the following:
1. Go to: AOT\Web\Web Files\StaticsFiles\defaultax
2. Export defaultax object
3. Make a backup copy
4. Edit this defaultax object, which is the master page, in NotePad for example
5. Import the new modified master page back into the AOT
6. Run AXUPDATEPORTAL.EXE to deploy the edited master page

Sunday, September 8, 2013

Form Method


FormDataSource.Init
This method initializes the data source and is called from the super() of FormRun.Init(). The method is only called once when the form opens. The main task for this method is to initialize the query used for fetching data. To modify or replace the query automatically created by the form, do this after
the super() call of this method.

FormDataSource.InitValue
This method is used to initialize a new record with default values. The super() of this method calls the initValue() method on the underlying table. If you have initialization that applies system-wide, put the code on the table.

FormDataSource.Active
This event is called when a new record becomes active in the data source. This method is typically overridden to change properties which depend on the contents of the current record: Commonly this method will:
Modify permissions to the data source
Modify permissions to the fields
Enable/Disable buttons

FormDataSource.LinkActive
This method is the engine that joins data sources. This method is called on the joined data source every time that the active record in the main data source is changed. The method is also called when the form is opened as the system tries to join the calling data source to the main data source of the called form.

FormDataSource.ValidateWrite
This method validates an insert or update of a record. The super() of this method calls the corresponding method on the underlying table. If you need to distinguish between an insert and update, make a condition on the RecId field, which only has a value if it is an update.

FormDataSource.Write

This method controls the insert and update of records. The super() of this method calls the corresponding method on the underlying table. If you have form-specific tasks to perform in relation to the commitment of the record, add it here.

Friday, September 6, 2013

Update Recordset


VendTable vendTable;

    ttsBegin;

    update_recordSet vendTable

        setting VendGroup = "GEN"

            where vendTable.VendGroup == "CORPORATE";

    ttsCommit;