Showing posts with label AX 2012. Show all posts
Showing posts with label AX 2012. Show all posts

Batch Job Schedule X++ D365FO


Batch Job Schedule D365FO


With the following X++ sample code you can schedule a Batch job.



Sample Code




static void batchJobSchedule(Args _args)
    {
        BatchHeader objBatchheader;
        SysRecurrenceData sysRecurrenceData;
        Batch batch;
        BatchJob batchJob;
        RetailCDXScheduleRunner objRetailSchedule;
        BatchInfo objBatchInfo;
        BatchRetries noOfRetriesOnFailure = 0;
        ;

        // Setup the RunBaseBatch Job
        objBatchheader = Batchheader::construct();
        objRetailSchedule = new RetailCDXScheduleRunner();
        objBatchInfo = objRetailSchedule.batchInfo();
        objBatchInfo.parmRetriesOnFailure(noOfRetriesOnFailure);
        objBatchInfo.parmCaption("Description should be here"); // Description Batch Job
        objBatchInfo.parmGroupId('YourBatchGroup'); // Batch Gorup
        objBatchInfo.parmBatchExecute(NoYes::Yes);
        objBatchheader.addTask(objRetailSchedule);

        // Set the recurrence data
        sysRecurrenceData = SysRecurrence::defaultRecurrence();
        SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData, DateTimeUtil::addSeconds(DateTimeUtil::utcNow(), 20)); // Set range of recurrence
        SysRecurrence::setRecurrenceNoEnd(sysRecurrenceData);
        SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::Minute); // Set reccurence pattern
        objBatchheader.parmRecurrenceData(sysRecurrenceData);
        // Set the batch alert configurations
        objBatchheader.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::Yes);
        objBatchheader.save();

        // Update the frequency to run the job to every two minutes
        ttsbegin;
        select forupdate batchJob
            join batch
            where batchJob.RecId == batch.BatchJobId
            && batch.ClassNumber == classnum(RetailConnScheduleRunner);

        sysRecurrenceData = batchJob.RecurrenceData;
        sysRecurrenceData = conpoke(sysRecurrenceData, 8, [10]);
        batchJob.RecurrenceData = sysRecurrenceData;
        batchJob.update();
        ttscommit;
    }


Enable AOS Authorization field using security privilege

Enable AOS Authorization field using security privilege 


Yesterday one of my team member were facing Access Denied error on some fields of table HcmPersonDetails while selecting the record. even she provide the complete rights on this table.




After spending few hours on this issue we found difference in fields properties.
AOS Authorization set as Yes.





Resolution

For the resolution, I have suggested her to add all the required fields in the privilege as well and perform build and sync the database. 





Please feel free to contact me if you are facing any issue while implementing of this blog.

Send Email in CC AX-2012


Send Email in CC AX-2012


Most of the developer have requirement in their project to send email in CC and in default Dynamics AX-2012 & D365FO this functionality is not available.


But there is the Standard class SysEmailDistributor which is responsible to send the complete AX emails.. we can achieve our goal and send email in CC as well..


Open the class and check the process method where you can find  object of SysMailerNet class.

 SysMailerNetAddressField tos,tocc;  // declare a variable <tocc>

 mailer = new SysMailerNet();  

 tocc=mailer.ccs();   // get the SysMailerNetAddressField  object using this method

tocc.add("ShaikhSohailHussain@gmail.com");  //add email address on which you want to send email as CC.



Please feel free to contact me if you are facing any issue during implementation of this blog

Simple Look Up D365FO - AX-2012


Simple Look Up D365FO - AX-2012


Simple Look Up
Today we learn Simple Look Up in just 4 Step
Step: 1
Create a form Then add StringEdit Control in Design and override the lookup method.




Step: 2
Copy Paste this Code in the lookup method




Step :3
Create a AOT Query . In this tutorial my query name is  LookUpFormQuery 




Step :4
Compile Complete Project and Run the form




How to get Employee Dimensions


How to get Employee Dimensions

Here is the sample code to find the dimension by Name. In the below sample code we are using cost center Dimension for searching.




static void job1(Args _args)
    {
        HcmEmployment                         hcmEmployment;
        DimensionAttributeValueSetItem  setItem;
        DimensionAttributeValue              dimAttrValue;
        DimensionAttribute                      dimAttribute;
        ;

        dimAttribute    = DimensionAttribute::findByName('CostCenter');

        while select hcmEmployment
              join RecId, DisplayValue from setItem
              where setItem.DimensionAttributeValueSet ==
              hcmEmployment.DefaultDimension
              join dimAttrValue
              where dimAttrValue.RecId == setItem.DimensionAttributeValue &&
              dimAttrValue.DimensionAttribute == dimAttribute.RecId       &&
              dimAttrValue.IsDeleted == false
        {
            info(strFmt("Employee = %1  %2 = %3 ",
           HcmWorker::find(hcmEmployment.Worker).PersonnelNumber,
           dimAttribute.Name, setItem.DisplayValue));
        }
    }

How to Get Current Company



How to Get Current Company

Hi,
Please use to get current logged in company with curExt();
Example :
static void curExtExample(Args _arg)
{
    str _CompanyId;
    ;
    _CompanyId= curExt();
      Info(_CompanyId);
}
You can also get the logged in company with below code
static void curExtExample(Args _arg)
{
    str _CompanyId;
    ;
   _CompanyId= CompanyInfo::Find().DataAreaId;
   Info(_CompanyId);
}

AIF Services Ax2012




AIF Services In few steps.




Today we learn how to create an AIF service

Step 1
Create a Table and add the below fields.
Fields:
  • Name
  • Phone

Screenshot reference:






Step 2
Create Two classes
  • Student Contract 
  • Student Service

Screenshot reference:





Step 3
Open Student Contract  Class Defines Variable and Create Get Set Method

Screenshot reference:







Step 4
Open Student Service Class

Screenshot reference:



In your student service class create two method
  • Insert Student
  • Get Student

Screenshot reference:



Get Student

Screenshot reference:




Step 5
Set your Student Service Class Run On server

Screenshot reference:




Step 6
Right Click on your project root node and select Service from the Submenu

Screenshot reference:




Step 7
Set the class reference on service properties

Screenshot reference:




Step 8
Then Expend the Service and right-click on the operation and select Add Operation

Screenshot reference:


Step 9
A window will appear now select the method you want to expose to the client in my case I am going to select both methods

Screenshot reference:



Step 10
Right-click on your project and Add a service group

Screenshot reference:




Step 11
Now drag and drop your service into the service group and compile the complete project. after compile right click on the service group and deploy the service group. below window will with deploy result

Screenshot reference:





Step 12
System administration/Area page. 

Screenshot reference:



From the below screen you can find your service External URL

Screenshot reference:





How to Test Service

Step 1
Open Visual Studio
Create a Console application
Step 2
Add Service Reference
Screenshot reference:






Step 3
Add following Code
Screenshot reference:




Step 4
Run Application. Hope the application will be working fine if you follow every step properly. :)

Screenshot reference:

Please feel free to contact me if you are facing any issues during the implementation of this blog.


Form Look Up



Form Look Up

Today, we Learn how to create Form Look Up
Step: 1
Create a Project and Add two forms.




Step :2
  • Add HCMWORKER table in SL_LookUp_Form Data Source.
  • Add Grid and Drag and Drop the two fields on the grid
Step :3
Set Personnel Number field Property : set as Auto Declaration to YES


Step :4
Now Compile the complete project then run the form.




Step :5
Now right click on Design node(not Designs) and set style property to LookUp.



Compile and Run again Form will look like the below image.



Step :6
Now override the init method of SL_Lookup_Form .



copy paste the below code.



Step:7
Now Select SL_First_Form
Create a Method with name of CustomLookup and copy paste the below code.




Step: 8
  • Add StringEdit Control in the Design.
  • After adding the StringEdit Control override the lookup method.
  • Copy paste the below code.


Step :9
Compile project and run SL_First_Form




Please feel free to contact me if you are facing any issue during implementation of this blog.










How to find or create default Dimension from X++ in AX 2012


How to find or create default Dimension from X++ in AX 2012


Following is the code you can use to find or create dimension in AX 2012


static DimensionDefault generateDefaultDimension(container _attr, container _value, boolean _createIfNotFound = true)
    {
        DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault result;
        int i;
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
        //_attr is dimension name in table DimensionAttribute
        container conAttr = _attr;
        container conValue = _value;
        str dimValue;

        for (i = 1; i <= conLen(conAttr); i++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));

            if (dimensionAttribute.RecId == 0)
            {
                continue;
            }

            dimValue = conPeek(conValue,i);

            if (dimValue != "")
            {
                // _createIfNotFound is "true". A dimensionAttributeValue record will be created if not found.
                dimensionAttributeValue=
                dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,_createIfNotFound);

                // Add the dimensionAttibuteValue to the default dimension
                valueSetStorage.addItem(dimensionAttributeValue);
            }
        }
        result = valueSetStorage.save();
        return result;
    }

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...