Показать сообщение отдельно
Старый 16.04.2007, 23:51   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Harish Mohanbabu: Table set / get properties
Источник: http://harish-m.livejournal.com/24306.html
==============
Ever since I changed job, it has been a busy period. Any way one of the questions I have noticed often is about setting and getting table properties by X++. This can be accomplised by using 'TreeNode' class. Here are some examples -

Get table properties
Let us say we want to get 'Security key' table property for all tables. Here is a sample code -

X++:
static void getTableProperty(Args _args)
{
/*
    Author      :       Harish Mohanbabu
    Date        :       April 16, 2007
    Purpose     :       To obtain table properties
*/

    #AOT
    str             Property;
    TreeNode        TreeNode;
    identifiername  identifiername;
    str             Name;
    ;

    TreeNode    = TreeNode::findNode(#TablesPath);
    TreeNode    = TreeNode.AOTfirstChild();
    while (TreeNode)
        {
            Name = TreeNode.AOTname();
            Property       = TreeNode.AOTgetProperties();
            identifiername = findproperty(Property, 'SecurityKey');
            info (strfmt("%1, %2", Name, identifiername));
            treenode = TreeNode.AOTnextSibling();
        }
}
Set table properties
Let us say we want to set 'modified date' table property to yes for all 'CustTable'.

......................................................
X++:
static void setTableProperty(Args _args)
{
/*
    Author     :       Harish Mohanbabu
    Date       :       April 16, 2007
    Purpose    :       To obtain table properties
*/

    str                Property;
    TreeNode    TreeNode;
    str               Name;
    ;
    
    Name = "CustTable";
    TreeNode  = TreeNode::findNode("Data Dictionary\\Tables\\" + Table);
    if (TreeNode)

           ttsbegin;
           Property       = TreeNode.AOTgetProperties();
           Property       = SetProperty(Property, "ModifiedDate", "Yes");
           TreeNode.AOTsetProperties(Property);
           TreeNode.AOTcompile();
           TreeNode.AOTsave();
        }
}
Note - if you are planning to use the above code, please make sure you first do this in a test environment.


==============
Источник: http://harish-m.livejournal.com/24306.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.