D365/AX7:Preceding & Succeeding Methods & Events Of Table

Preceding & Succeeding Methods & Events Of Table

  1. ValidateWrite, ValidatingWrite & ValidatedWrite
  2. ValidateDelete, ValidatingDelete & ValidatedDelete
  3. ValidateField, ValidatingField & ValidatedField
  4. ValidateFieldValue, ValidatingFieldValue & ValidatedFieldValue
  5. modifiedFieldValue, ModifyingFieldValue & ModifiedFieldValue
  6. modifiedField, ModifyingField & ModifiedField
  7. Insert, Inserting & Inserted
  8. Delete, Deleting & Deleted
  9. InitValue, InitializingRecord & InitializedRecord

MethodsEventsOfTable.PNG

D365/AX7:EvalBuf() Alternative & Replacement – Evaluate complex algebraic expressions

Purpose

Calculate & evaluate complex algebraic expressions given in a string.

For example

str expression = “((12 + 2/2)*2)-6”;

After calculation above expression, result should come 20.

Issue

In Microsoft dynamics AX 2012,  EvalBuf() function was available for calculating complex algebraic expression.But in D365 finance and operation the function evalBuf() is missing and you cannot use it anymore.

Solution with sample code

We can use ProdMathEvaluator::evaluate() instead of EvalBuf().

[code language = “cpp”]
str expression = “((12 + 2/2)*2)-6”;
info(strFmt(‘%1’, ProdMathEvaluator::evaluate(expression)));
[/code]

Note

The expression string should not comma separator “,” etc otherwise you will get below error

“Misuse of “Our expression”, Please review the elements and symbols used in the equation.”

[code language = “cpp”]
str expression = “((12 + 2/2)*2)-6”;
expression = strRem(expression, “,”); // removing comma
info(strFmt(‘%1’, ProdMathEvaluator::evaluate(expression)));
[/code]

 

cheers 🙂

piyush adhikari

D365/AX7:Adding a new custom number sequence in standard modules or parameters form using COC

Purpose

Adding a new custom number sequence in Accounts payable – Setup – Accounts payable parameters using COC-chain of commands.

Sample Code & Instructions

  1. Create a new extension class of table VendParmeters and a new method.

[code language = “cpp”]
[ExtensionOf(tableStr(VendParameters))]
final class VendParameters_Extension
{
public static NumberSequenceReference vendGroupId()
{
return NumberSeqReference::findReference(extendedTypeNum(VendGroupId));
}
}
[/code]

 

2. Create a new extension class of NumberSeqModuleVendor.

[code language = “cpp”]
[ExtensionOf(classStr(NumberSeqModuleVendor))]
final class NumberSeqModuleVendor_Extension
{
protected void loadModule()
{
NumberSeqDatatype datatype = NumberSeqDatatype::construct();
next loadModule();
datatype.parmDatatypeId(extendedTypeNum(VendGroupId));
datatype.parmReferenceHelp(literalStr(“@SYS53981”));
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardFetchAheadQty(10);
datatype.parmWizardIsChangeDownAllowed(NoYes::No);
datatype.parmWizardIsChangeUpAllowed(NoYes::No);
datatype.parmWizardHighest(999999);
datatype.parmSortField(1);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
}
}

[/code]

3. Create a runnable class NumberSeqModuleVendorRunnableClass which will                   load   the number sequences.

[code language = “cpp”]
class NumberSeqModuleVendorRunnableClass
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = “_args”>The specified arguments.</param>
public static void main(Args _args)
{
NumberSeqModuleVendor loadModule = new NumberSeqModuleVendor();
;
loadModule.load();
}
}
[/code]

 

4. At last, run the runnable class and then go to Organization administration – Number sequences – Number sequences – Generate Button (Run the wizard and complete it)

cheers 🙂

piyush adhikari

D365/AX7:Display Method In Table Extension Of Standard or Base Table

Purpose

Writing Display Method In Table Extension Of Standard or Base Table.For example:Writing display in table extension “VendTable”.

Sample Code & Instruction:

  1. Create a new extension class for table.
  2. Write a new display method and also define method attribute [SysClientCacheDataMethodAttribute]
  3. Add a form control in form and change the properties as per below screenshot

[code language = “cpp”]
[ExtensionOf(tableStr(VendTable))]
final public class ACXVendTable_Extension
{
public static display Description vendorGroupName(VendTable _this)
{
return VendGroup::find(_this.VendGroup).Name;
}
}
[/code]

 

untitled

 

cheers 🙂

piyush adhikari

D365/AX7:Form Datasource Field Event or Data Event “onValidating”

Purpose

Demonstration of Form Datasource Field Event or Data Event “onValidating”.Validating field values in form level.

Sample Code

  1. Create a new class.
  2. Copy “onValidating” event from Form Datasource field & paste the same into the class.

[code language = “cpp”]
[FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, SalesPrice), FormDataFieldEventType::Validating)]
public static void SalesPrice_OnValidating(FormDataObject sender, FormDataFieldEventArgs e)
{
var args = e as FormDataFieldCancelEventArgs;
FormRun formRun = sender.datasource().formRun();
boolean ret;
SalesTable salesTable = formRun.dataSource(formdatasourcestr(SalesTable, SalesTable)).cursor();
SalesLine salesLine = formRun.dataSource(formdatasourcestr(SalesTable, SalesLine)).cursor();
formRun = sender.datasource().formRun();
if (CustTable::find(salesTable.CustAccount).AcxOverrideSalesPrice == NoYes::Yes && salesLine.SalesQty > 0)
{
ret = checkFailed(‘Override Sales Price Is True On Customer Card.’);
args.cancel(true);
}
}
[/code]

cheers 🙂
piyush adhikari

D365/AX7:Customizing & Writing Event Handler “onModifyingField” Of Table using switch statement of FieldId

Purpose

Customizing & Writing Event Handlers Of Table in Microsoft Dynamics D365/AX7. Modifying table field values using switch statement of FieldId

Sample Code

[code language = “cpp”]

[DataEventHandler(tableStr(PurchLine), DataEventType::ModifyingField)]
public static void PurchLine_onModifyingField(Common sender, DataEventArgs e)
{
PurchLine purchLine = sender;
AcxDesigns acxDesigns;
ModifyFieldEventArgs modifyFieldEventargs = e as ModifyFieldEventArgs;
AcxWeightRangeMaster weightRangeMater;
;

switch(ModifyFieldEventArgs.parmFieldId())
{
case (fieldNum(PurchLine, AcxDesignCode)):
select firstonly1 AcxDesigns
where AcxDesigns.DesignCode == PurchLine.AcxDesignCode;
purchLine.AcxOrnamentCategoryCode = AcxDesigns.OrnamentCategoryCode;
purchLine.AcxOrnamentSubCategoryCode = AcxDesigns.OrnamentSubCategoryCode;
break;

default:
break;
}
}

[/code]

cheers 🙂
piyush adhikari

D365/AX7:Customizing & Writing Event Handler “onValidatedField” Of Table using switch statement of FieldId

Purpose

Customizing & Writing Event Handlers Of Table in Microsoft Dynamics D365/AX7. Validating table field values using switch statement of FieldId

Sample Code

[code language = “cpp”]

[DataEventHandler(tableStr(PurchLine), DataEventType::ValidatedField)]
public static void PurchLine_onValidatedField(Common sender, DataEventArgs e)
{
PurchLine purchLine = sender;
ValidateFieldEventArgs validateFieldEventArgs = e as ValidateFieldEventArgs;
boolean ret = ValidatefieldEventargs.parmValidateResult();
;

if (ret)
{
switch (validateFieldEventArgs.parmFieldId())
{
case fieldNum(PurchLine, ItemId):
InventTable inventTable = InventTable::find(PurchLine.itemId);
if (InventTable.ACXPOType != PurchLine.purchTable().ACXPOType)
ret = checkFailed(‘Purchase Order Header PO Type Should Be Same As Item PO Type’);
break;
default:
break;
}
ret = ValidatefieldEventargs.parmValidateResult(ret);
}
}

[/code]