4 Aug 2016

Check Employee dimension through code + AX 2012

Hi Folks,

Recently my client face problem with Employee dimension.

Issue::

My client doing some functionality for that employee required some mandatory dimensions( Branch , Segment, Projects,  BusinessUnits) but some employees don't have dimensions.

There are almost 2000 employees, it's not a easy task to check every employee for dimensions,
For that he asked me write a job for who don't have particular dimensions ( Branch , Segment, Projects,  BusinessUnits).

Solution::

static void  ExplorerGetdefaultdim(Args _args)
{
    HcmEmployment       hcmEmployment,hcmEmploymentloc;
    str                 id;
    str                 res;
    boolean             checkproj= true;
    boolean             checkbranch= true;
    boolean             checksegme= true;
    boolean             checkbussunit = true;
    DimensionAttributeValueSetStorage    dimStorage;
    Counter              i;




     while select * from hcmEmployment where hcmEmployment.DefaultDimension != 0
        // some employees don't have any dimensions i m not bothering about who don't have any //dimensions
    {
        select hcmEmploymentloc order by hcmEmploymentloc.RecId  desc where hcmEmploymentloc.Worker == hcmEmployment.Worker;

        checkbranch= true;
              checksegme= true;
              checkbussunit = true;
        dimStorage = DimensionAttributeValueSetStorage::find(hcmEmploymentloc.DefaultDimension);
        checkproj= true;
       
        for (i=1 ; i<= dimStorage.elements() ; i++)
        {
          //info(strFmt("Worker :%1,Dimension :%2,Value :%3",hcmEmployment.Worker,DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name +"----" +dimStorage.getDisplayValueByIndex(i)));  // if u want to see employee all dimensions

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Branch")
            {
                checkbranch = false;
                   
            }
            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Segment")
            {
                checksegme =false;
                     
            }
            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "Projects")
            {
                checkproj =false;
                   
            }
            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == "BusinessUnits")
            {
                checkbussunit = false;
         
            }
 
        }
            if(checkbussunit == true ||checkproj == true|| checkbranch == true ||checksegme == true)
              {
                info(strFmt("Errors result  %1",HcmWorker::find(hcmEmployment.Worker).name()));
            }
       
    }
}

No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...