AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 10.05.2008, 19:14   #1  
Blog bot is offline
Blog bot
Участник
 
25,631 / 848 (80) +++++++
Регистрация: 28.10.2006
casperkamal: Using record templates in code for Dynamics Ax 4.0.
Источник: http://casperkamal.spaces.live.com/B...CD63!398.entry
==============


This article deals with defaulting values from record templates through code in Dynamics Ax 4.0.
 
Whenever you creat a new record in the Item form, a small form opens up showing up the templates. You can choose one of the templates from which you want to the basic values like "Item Group", "Dimension Group" to be copied.(Provided you have setup a template for that table).
 


  This comes handy to create new records further as most of the value is drawn from the template record itself. You can harness this when you do it through code also :) ....  The following lines will throw light on how to do it.
 
1. Assume that you have the template name, then all that you need is to create a new record based on the template.
These three lines will do the job...

sysRecordTemplate = SysRecordTemplate::newCommon(inventTable); sysRecordTemplate.parmForceCompanyTemplate('Feed'); //Template name as string sysRecordTemplate.createRecord();There are two kind of templates one common for the entire company and the other for specific user. In my example i have taken the company template, for the simple reason that it is valid across all accounts.
 
2. The above code pressumes that you might know the template name in prior. Sometimes you may want to give user a option of telling what template he wants to use. In that case we may need to create a template for him.

Here is the code that will enable the lookup and validate the selection. Bind these methods to the control where the user selects.
 
//Call this method in the init method of form
SysRecordTmpTemplate VCTInitItemTemplates()
{
    Container               recordValues;
    ;

    recordValues = SysRecordTemplateTable::find(tablenum(inventTable)).Data;
    recordValues =  condel(recordValues,1,1);
    //tmp1 - Global variable for lookup   
    SysRecordTmpTemplate::insertContainer(tablenum(inventTable), tmp1, recordValues, SysRecordTemplateType::Company, true);
    //tmp2 - Global variable for validation
    SysRecordTmpTemplate::insertContainer(tablenum(inventTable), tmp2, recordValues, SysRecordTemplateType::Company, true);
    return tmp;
}



//Override the lookup method
public void lookup()
{
    SysTableLookup          sysTableLookup;
    SysRecordTmpTemplate    tmp;
    Container               recordValues;
    ;

    super();
  
    sysTableLookup = SysTableLookup::newParameters(tablenum(SysRecordTmpTemplate), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(SysRecordTmpTemplate, Description), true);

    sysTableLookup.parmUseLookupValue(false);
    sysTableLookup.parmTmpBuffer(tmp2);
    // Perform lookup
    sysTableLookup.performFormLookup();
}      

//Override the modified methodpublic boolean modified(){ boolean ret; SysRecordTmpTemplate tmp; container recordValues; ; ret = super(); select firstonly tmp2 where tmp2.Description == this.valueStr(); if (!tmp2 && this.valueStr()) { this.text(''); warning ('Invalid selection.'); return false; } return ret;}
 
This also helps you learn usage of temporary tables for lookup's. The following line enables lookups through temporary table.
 
sysTableLookup.parmTmpBuffer(tmp2);
 
Hope now you can implement a full fledged code that will create it's record from an pre exisiting template.
 
----------- any template for codes where i can just get all the code that i want


Источник: http://casperkamal.spaces.live.com/B...CD63!398.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
casperkamal: Sending alerts through code without error in Ax Blog bot DAX Blogs 0 24.03.2008 21:05
casperkamal: A small addition to creation of Table throug x++ code in Dynamics Ax Blog bot DAX Blogs 0 03.04.2007 23:11
casperkamal: Adding a Table field through X++ code in Dynamics Ax Blog bot DAX Blogs 1 02.04.2007 17:05
casperkamal: Using Script to create code for inserting record in a table Blog bot DAX Blogs 1 13.02.2007 12:57
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 07:03.