Sunday, 23 September 2012

Finding unused labels in Dynamics Ax 2009

static void FindUnUsedLabels()
{
    str 50          labelId;
    str             labelString;
    int             i;
    //set max label to the highest number of labelId in your application
    int             maxLabel = 2000;
    xRefNames       names;
    XRefReferences  ref;

    ;

    while (i <= maxLabel)  
    {
        //Sequential generation
        labelId = "@IFC" + int2str(i);
        
        //Find if the label id has an cross reference
        //record
        select recid from names
            where names.Name == labelid
        exists join ref
            where names.RecId == ref.xRefNameRecId;

        labelString = SysLabel::labelId2String(labelId);
        
        //If there is no record in cross reference then log it
        if (! names.RecId &&
        //avoid logging labels that are already deleted (This is because of sequential check like IFC1, IFC2, IFC3 etc...)
            labelString != labelId)
        {
            info(strfmt("%1 - %2\n", labelId, SysLabel::labelId2String(labelId)));
        }

        i++;
    }

}

No comments:

Post a Comment