find Or Create TimeStamp in dynamics ax

Description:-

In this example we will see about how to create or find timestamp in dynamics ax. here is the job to fin or create timestamp in dynamics ax.

Code:-
private void findOrCreateTimeStamp(SysVersionControlTmpItem   _item)
{
strtimeStamp;
UtilElementsutilElement;
SysDictClassdictClass;
ClassBuildclassBuild;
SysVersionControlTmpItem        item            = _item;
strmethodName      = "csGetVersion";
int                             time            = timenow();
TreeNodetreeNode        = TreeNode::findNode(item.ItemPath);

utilElement = treeNode.utilElement();            

timeStamp   = date2Str(
today(),
                        321,
DateDay::Digits2,
DateSeparator::Slash, 
DateMonth::Digits2,
DateSeparator::Slash,
DateYear::Digits4,
DateFlags::None);

timeStamp   = timeStamp + "_"                                           +
num2str0(time div 3600, 2, 0, 0, 0) + "_"           +
num2Str0(time mod 3600 div 60, 2, 0, 0, 0) + "_"    +
num2Str0(time mod 3600 mod 60, 2, 0, 0, 0);

if (utilElement.recordType == UtilElementType::Class)
    {
dictClass   = new SysDictClass(className2Id(utilElement.name));
classBuild  = new ClassBuild(utilElement.name, true);

if (dictClass.hasStaticMethod(methodName))
        {
            //Override method here, since the method already exists in the component.
classBuild.overrideMethod(methodName,
                                        @"public static strcsGetVersion()" +
                                        "{"                                 +
                                            "return '" + timeStamp + "';"   +
                                        "}"); 
        }
else
        {
            //Make a new method here since it does'nt exist in the component.
classBuild.addMethod(methodName,
                                        @"public static strcsGetVersion()" +
                                        "{"                                 +
                                            "return '" + timeStamp + "';"   +
                                        "}"); 
        }

classBuild.classNode().AOTcompile();    
    }
}

The above method is created by referring to previous answer and other professionals. It validates if the method exists in the class first. If found it overrides else creates new method. For other elements like Tables, Forms and Maps we can implement in the similar way.

Related Posts

Previous
Next Post »

Thanks for comments.....