Monday 3 March 2014

Check Any record exists in given date Range while inserting a record

In Validate write of Table or Form Datasource

public boolean validateWrite()
{
    boolean                     ret;
    SCPProductPossessionCharges scpProductPossessionChargesloc;

    if (SCPProductPossessionCharges.FromDate > SCPProductPossessionCharges.ToDate)
    {
        error("@GLS90176");
        return false;
    }

  while select scpProductPossessionChargesloc
       where scpProductPossessionChargesloc.ItemId == SCPProductPossessionCharges.ItemId
          && scpProductPossessionChargesloc.SCPPossessionCharges == SCPProductPossessionCharges.SCPPossessionCharges
          && scpProductPossessionChargesloc.RecId != SCPProductPossessionCharges.RecId
    {
       ret = element.checkDateOverlap(SCPProductPossessionCharges,scpProductPossessionChargesloc);
        if(!ret)
        {
            error("@SCP353");//A record already exists for given date range
            return ret;
        }
    }

    ret = super();

    return ret;
}


one public method checkDateOverlap(newrecord,existingRecord)

public boolean checkDateOverlap(
    scpProductPossessionCharges _curVersion ,
    scpProductPossessionCharges _checkAgainstVersion )
{

        if ((_curVersion.ToDate   >= _checkAgainstVersion.FromDate || !_curVersion.ToDate) &&
            (_curVersion.FromDate <= _checkAgainstVersion.ToDate   || !_checkAgainstVersion.ToDate))
        {
            return false;
        }

        if (   _checkAgainstVersion.ToDate   >= _curVersion.FromDate
            && _checkAgainstVersion.FromDate <= _curVersion.ToDate)
        {
            return false;
        }


    return true;

}





Tuesday 16 July 2013

Work flow in easy steps


http://learnax.blogspot.in/2012/01/dynamics-ax-2012-workflow-development.html
http://www.amer-ax.com/2010/07/create-workflow-in-three-easy-steps-by-workflow-for-dummies/

Tuesday 6 November 2012

Only 2 clicks to get help on how to use functions with example [In Editor]

This post will be very helpful for the developers who are new and are looking for an example on how to use a functions with an example . Usually any developer who is very new to Dynamics AX will go to AOT >> System Documentation >> functions and will select a function >> right clicks and use edit option to get help on the function and example if any.
Well, I know its very boring way to go always to that level and get help. I have modified Editorscripts class again to get quick help in the editor itself.
All you need to do is add the below method “ShowExample” to the EditorScripts class

public void ShowExample(Editor editor)
{
str line;
int i;
int startLine = editor.selectionStartLine();
int endLine = editor.selectionEndLine();
int startCol = editor.selectionStartCol(); //points at the first selected char
int endCol = editor.selectionEndCol()-1; //points at the last selected char
MarkMode markMode = editor.markMode();
#define.maxLineLength(300)
#AOT
Form formBrowse;
FormHTMLControl htmlControl;
FormRun formRun;
Args args;
str htmlContent;
TreeNode functionTreeNode;
Editor _editor = editor;
str h1Tag;
void transform(str _function)
{
;
functionTreeNode = TreeNode::findNode(#SystemFunctionsPath+’\\’+_function);
if (!functionTreeNode)
throw error (“Function not found in System documentation”);
formBrowse = new Form(‘Function Example’, true);
formBrowse.design().caption(_function + ” Example”);
formBrowse.design().width(700);
formBrowse.design().height(500);
formBrowse.design().addControl(FormControlType::HTML, ‘html’);
args = new Args(formBrowse.name());
args.name(formBrowse.name());
args.object(formBrowse);
formRun = classFactory.formRunClass(args);
formRun.init();
htmlControl = formRun.design().controlName(‘html’);
htmlControl.height(1,1);
htmlControl.width(1,1);
formRun.run();
htmlControl.setText(functionTreeNode.AOTgetSource());
formRun.detach();
}
void transformLine(int lineNo, int start, int end)
{
_editor.gotoCol(0);
_editor.gotoLine(lineNo);
line = _editor.currentLine();
transform(substr(line, start, end-start+1)) ;
return;
}
;
editor.unmark();
switch (markMode)
{
case MarkMode::LineMark:
editor.gotoCol(1);
for (i=startLine; i<=endLine; i++)
{
transformLine(i, 1, #maxLineLength);
}
break;
case MarkMode::ColMark:
for (i=startLine; i<=endLine; i++)
{
transformLine(i, startCol, endCol);
}
break;
case MarkMode::AreaMark:
if (startLine == endLine)
{
transformLine(startLine, startCol, endCol);
}
else
{
//convert first line
transformLine(startLine, startCol, #maxLineLength);
//convert full lines
for (i=startLine+1; i<endLine; i++)
{
transformLine(i, 1, #maxLineLength);
}
//convert last line
transformLine(endLine, 1, endCol);
}
break;
}
}

Wondering how to use it now.
Create a new job and write any function. In the below example I have shown this by using strfmt function. Double click the function and select scripts button>> Show example as shown below

There you go. you will get help on how to use this function with an example on your screen. Isn’t it helpful?? Below is the output form which gives you quick help on the functions. You can get the help for any function which is defined in system documentation.

Friday 2 November 2012

Use resource files in Axapta

Axapta provides a very handy feature to allow developers to ship their solution with Axapta built-in image files. In Application Object Tree, you can find resources node. Select resources node and right click; select Create from File, specify the file location for the new resource file. After that you can use this resource file in Axapta without specifying an absolute file path in your hard disk.
Then let’s see how to use this kind of files in Axapta.
First, pick up the resource node from AOT;
SysResource::getResourceNode();
Then generate a temporary file for this resource file;
SysResource::saveToTempFile()
Finally specify the temporary file path for controls.
Here comes an example to show how to use a resource file as a background image of  a given form.
    {        ResourceNode            resourceNode;
        FilePath  imagename;
        ;
        resourceNode = SysResource::getResourceNode(resourcestr(ResourceName)); 
        if (resourceNode)
        {
            resourceNode. AOTload();
            imagename =  SysResource::saveToTempFile(resourceNode);
        }
        else
        {
             throw Error("No file exists.")
        }
        element.design().imageName(imagename);
    }

Monday 15 October 2012

Creating a new line in a grid using command button



under click method of command button use the following code;

void clicked()
{
   <tablename>_ds.create(true);
   super();
}