10.05.2008, 19:14 | #1 |
Участник
|
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, напишите личное сообщение администратору. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|