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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 03.10.2015, 02:35   #1  
Blog bot is offline
Blog bot
Участник
 
22,309 / 771 (70) +++++++
Регистрация: 28.10.2006
How to lookup and set a new value for Financial dimension
Источник: http://alexvoy.blogspot.com/2015/10/...value-for.html
==============

Let's say we need to change a value for one of item financial dimension.

I created a simple form with the item list and their default financial dimensions that are controlled by a standard controller.



There are also two unbound controls that allows to select any related financial dimension attribute and its available value. It is done by means of two edit methods and one lookup method, which can be added to your class and used everywhere you need.


A new chosen value can be set for the item financial dimension by the Set new value button. Actually it uses a method that, again, can be added to your class a static one.

I would like to thank Carsten Glem for his comment on this topic.

Here comes the code for the main methods. Feel free also to download the whole project.




Form class declaration
public class FormRun extends ObjectRun
{
// Standard controller placing predefined financial attributes on a form tab page (FinDimTab in this example)
DimensionDefaultingController dimensionDefaultingController;
// New financial dimension attribute; placed on the form as an unbound control through its name and edit method
// via editAttributeToChangeName
DimensionAttributeRecId attributeToChange;
Name attributeToChangeName;
// New value for a chosen financial dimension attribute; placed as an unbound control through edit method
// via editAttributeToChangeValue
DimensionValue attributeToChangeValue;

// each time user change the attribute name, it changes attribute, if valid name, and clears its value on the form
// the lookup method LookupDimensionValueByAttribute can be placed in a class as a static to be used everywhere

// Set new value button calls SetDefaultDimensionValue method,
// which can actually be added to a class in a class as a static to be used everywhere
}LookupDimensionValueByAttribute

///
/// Creates and displays a lookup from which the user can select for parent category.
///
///
/// The calling form reference control.
///
///
/// The RecId of parent category
///
///
/// The selected record in the case of record mode selection; otherwise null.
///
public void LookupDimensionValueByAttribute(FormStringControl _formControl, str _dimensionAttributeValueStr, DimensionAttribute _dimensionAttribute)
{
Args args;
FormRun lookupFormRun;
Object object;

if (_formControl != null && _dimensionAttribute)
{
// Construct arguments for the custom lookup
args = new Args();
args.name(formStr(DimensionDefaultingLookup));
args.lookupValue(_dimensionAttributeValueStr);
args.caller(_formControl);

args.lookupField(_dimensionAttribute.ValueAttribute);
args.record(_dimensionAttribute);

// Run the custom lookup and init the lookup form
lookupFormRun = classfactory.formRunClass(args);
lookupFormRun.init();

// Specify this is the callback on the lookup form by casting the
// form to an object and late binding the setResultCallback method
if (SysFormRun::hasMethod(lookupFormRun, identifierStr(setResultCallback)))
{
object = lookupFormRun;
object.setResultCallback();
}

_formControl.performFormLookup(lookupFormRun);
}
}SetDefaultDimensionValue

///
/// Sets a value in a default dimension field of a given record, i.e. InventTable, CustTable etc.
///
///
/// DimensionDefault field from the existing record, i.e. InventTable.DefaultDimension.
///
///
/// The name of the dimension attribute to set the value for.
///
///
/// The new value for the given dimension attribute.
///
///
/// The new default dimension.
///
/// Note: taken from https://sumitsaxfactor.wordpress.com...sions-ax-2012/
public DimensionDefault SetDefaultDimensionValue( DimensionDefault _fromDefaultDimension,
Name _attributeName,
Str _newDimAttributeValue)
{
DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
DimensionAttributeValue dimensionAttributeValue;
DimensionDefault toDefaultDimension;
Map dimensionSpecifiers = DimensionDefaultingEngine::getDefaultDimensionSpecifiers(_fromDefaultDimension);
MapEnumerator enumerator;
DimensionAttribute dimensionAttribute;

//Add current dimension attribute values
enumerator = dimensionSpecifiers.getEnumerator();
while (enumerator.moveNext())
{
dimensionAttribute = DimensionAttribute::find(enumerator.currentKey());
dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName(dimensionAttribute.Name), enumerator.currentValue());
dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);
}

//Add the extra dimension attribute values
dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName(_attributeName), _newDimAttributeValue, true, true);
dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue); // Replaces since attribute already exists with different value
toDefaultDimension = dimensionAttributeValueSetStorage.save();

return toDefaultDimension;
}


Источник: http://alexvoy.blogspot.com/2015/10/...value-for.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
sumitsaxfactor: Replacing Financial Dimension in Ledger Dimension Blog bot DAX Blogs 0 19.01.2012 13:11
javascripterrors: CRM 2011 - Get and Set Lookup Values Using Java Script Blog bot Dynamics CRM: Blogs 0 28.06.2011 13:11
Khue Trinh: Setting up a link between a financial dimension and the site inventory dimension Blog bot DAX Blogs 0 27.09.2010 13:05
CRM DE LA CREME! Some more useful javascripts for MS CRM Blog bot Dynamics CRM: Blogs 0 04.05.2010 11:05
palleagermark: Data Set lookups on Enterprise Portal (EP) Blog bot DAX Blogs 0 20.12.2009 11:06
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 12:17.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.