lunedì 22 febbraio 2016

HOWTO: Set translation of label on fly by code

Use this script to set the value and comment of an existing label only if this label not exist in a particolar language. You can use it on fly by code whitout use of developer tool.
In my case i can set more than 200+ labels traduction in a couple of minutes.

void modifyLabel(LabelId _labelId, str _srcLanguage, str _trgLanguace, str _trgString, str _trgComment = '')
    {
        SysLabel      srcLang = new SysLabel(_srcLanguage);
        SysLabel      trgLang = new SysLabel(_trgLanguace);

        ;
        _labelId = "@" + _labelId;
        if (!srcLang.exists(_labelId) || !srcLang.extractString(_labelId))
        {
            warning(strfmt("L'etichetta %1 non esiste nella lingua %2", _labelId, srcLang.languageId()));
            return;
        }

        if (trgLang.exists(_labelId) && trgLang.extractString(_labelId))
        {
            warning(strfmt("L'etichetta %1 esiste già nella lingua %2 con il valore %3", _labelId, trgLang.languageId(), trgLang.extractString(_labelId)));
            return;
        }

        cnt += trgLang.modify(_labelId, _trgString, _trgComment ? _trgComment : srcLang.extractComment(_labelId));
        info(strFmt("Modificata etichetta %1 e impostato il testo %2 in lingua %2", _labelId, _trgString));
    }

This script can semplify the same action but in more than one language, example in my case the traduction of en-us and en-gb is the same.

    void modifyLabelMultipleLanguagese(LabelId _labelId, str _srcLanguage, container _trgLanguaces, str _trgString, str _trgComment = '')
    {
        int i;
        str trgLanguace;
        ;
        for(i=1;i<=conlen(_trgLanguaces);i++)
        {
            trgLanguace = conpeek(_trgLanguaces, i);
            modifyLabel(_labelId, _srcLanguage, trgLanguace, _trgString, _trgComment);
        }
    }

venerdì 12 febbraio 2016

HOWTO: Get error details from INFOLOG by code

You can use this code for getting che last error from INFO LOG.
I tested this code in all situations, using prefix and other conditions, and it works fine.
In the past i found some other scripts to do that, but i some situations does not work.

int i;
container infoLogCon;
container infoLogItem;
Exception infoLogItemExceptionType;
str infoLogItemMessage;
str strInfoLogMessage;
;
try
{
 infologCon = infolog.copy(1, infolog.line());
 for(i = infolog.line() + 1; i > 1; i--)
 {
  infoLogItem = conpeek(infologCon, i);
  infoLogItemExceptionType = conpeek(infoLogItem, 1);
  infoLogItemMessage = conpeek(infoLogItem, 2);
  if (infoLogItemExceptionType == Exception::Error)
  {
   strInfoLogMessage = infoLogItemMessage;
   strInfoLogMessage = strreplace(strInfoLogMessage, '\t', ' - ');
   break;
  }
 }
 if (!strInfoLogMessage)
  strInfoLogMessage = "Errore non definito";
}
catch
{
 strInfoLogMessage = "Errore sconosciuto";
}
strInfoLogMessage = strltrim(strrtrim(strInfoLogMessage));

lunedì 1 febbraio 2016

HOWTO: [AX2009] Update PURCHQTY of a PURCHLINE

Use this script for update the purchase quantity of a purchline

ttsbegin;
_pLine.PurchQty = q;
PurchLine::modifyPurchQty(_pLine, InventDim::find(_pLine.InventDimId), avoidBox);
InventMovement::bufferSetRemainQty(_pLine);
_pLine.update();
ttscommit;

venerdì 20 novembre 2015

X++: Find a shared project by name

This code allow you to search a project by name

ProjectListNode projectListNode;
TreeNodeIterator treeNodeIterator;
TreeNode treeNode;
str projectName;
;

projectName = "*xxx*";
projectListNode = SysTreeNode::getSharedProject();
treeNodeIterator = projectListNode.AOTiterator();
treeNode = treeNodeIterator.next();
while(treeNode)
{
  if (treeNode.AOTname() like projectName)
    info(treeNode.AOTname());
  treeNode = treeNodeIterator.next();
}

mercoledì 11 novembre 2015

HOWTO: Turning off the Synchronize Database form on Dynamics AX 2012

It is possible that the Synchronize Database form is now showing up unexpectedly during some of your scripts, if so you can programmatically set it on or off using the SysSqlSync ShowSysSqlSync global cache setting, here is a job that will turn off the form and automatically synchronize:
static void ShowSysSqlSync(Args _args)
{
    SysGlobalCache gc;
    str owner = 'SysSqlSync';
    str key   = 'ShowSysSqlSync';
    boolean showEnabled = false; //set to true to enable.
    ;
    gc = appl.globalCache();
    gc.set(owner, key, showEnabled);
    info(strfmt('Show SqlSync: %1', gc.get(owner, key))); 
}

giovedì 1 ottobre 2015

TIP: InventSum don't update ModifiedDateTime and ModifedBy fields

On my project i need to know how InventSum are updated , but when i activate the modified datetime the field this has no be automatic updated.
Than, thanks to this post http://blogs.technet.com/b/dynamicsaxse/archive/2010/12/29/fields-modifieddatetime-and-modifiedby-on-table-inventsum.aspx, i found a good solution.

Warning:, it's a kernel solution, than use it with care.

The InventSum update is made by a class, the InventUpdateOnHand
On this classe there is a method that build a SQL statement for the UPDATE of InventSum table.
I made a customization here and add on the UPDATE statement the MODIFIED fields.
There customization are made only for SQL server database.

Here the XPO of customization:
https://drive.google.com/open?id=0B3gigtHeLE6gY1pLVEVNcUpvLTA

On the method sqlUpdateStr you can comment out the IF clause to debug it on runtime, remember to comment out on production env.

martedì 30 giugno 2015

HOWTO: Detecting default values

So I haven’t posted in a long time. I finally fixed some technical issues on the blog and upgraded to a recent version of WordPress. Let’s start with a quick tip to warm up :)
As you know X++ supports methods with default values. In Ax it’s possible to detect when such a default value was used at runtime with prmIsDefault(). To see this for yourself, create a class with a method like this:

void someMethod(int i = 1)
{
    ;
 
    if (prmIsDefault(i))
    {
        info('Default');
    }
    else
    {
        info('Value given');
    }
}
 
And call it from another method.
    o.someMethod();
    o.someMethod(1);
 
Even though the value is the same in both cases a different info message will be displayed.
Now you may be wondering how this can be useful. Some scenarios:
  • Avoiding expensive operations if the default value was used
  • Avoiding unwanted initializations
  • Dealing with customizations that require extra parameters in standard Ax classes
If you do a search for prmIsDefault() in the AOT you will see it’s used often. Classes with the Ax prefix are the most obvious example. Because getters and setters are rolled into a single method it’s necessary to know if the method was used as a getter or a setter and keep track of modified fields.

Reposted from http://sysdictcoder.com/detecting-default-values/

AX 2012: The request was aborted: Could not create SSL/TLS secure channel

The error you're encountering, "The request was aborted: Could not create SSL/TLS secure channel," can occur due to various re...