Wednesday, November 22, 2017

HOW TO GET DAY OF THE WEEK IN MICROSOFT DYNAMICS AX

HOW TO CONSUME EXTERNAL WEBSERVICES 
IN MICROSOFT DYNAMICS AX 
Firstly add a service reference and then use that service reference in the below code to consume the web services.

// This job uses an external service to run a Bing search 
// The search string is “Dynamics AX” 
static void CallBingService(Args _args) 
{ 
// Replace the string [YOUR_BING_APPID] with your Application ID.
#define.AppId([YOUR_BING_APPID])

// This is the variable for the service client. 
ClrObject clientType; 

// This is the variable for the service client type. 
BingSearch.ServiceReferences.BingV2ServiceReference.BingPortTypeClient _client;

// These are the variables for web query objects. 
BingSearch.ServiceReferences.BingV2ServiceReference.SearchRequest request; 
BingSearch.ServiceReferences.BingV2ServiceReference.SourceType[] sourceTypes; 
BingSearch.ServiceReferences.BingV2ServiceReference.SearchResponse response; 
BingSearch.ServiceReferences.BingV2ServiceReference.WebResponse webResponse; 
BingSearch.ServiceReferences.BingV2ServiceReference.WebResult[] webResults; 
BingSearch.ServiceReferences.BingV2ServiceReference.WebResult webResult;
int integer; 
str string; 
System.Exception ex; 
new InteropPermission(InteropKind::ClrInterop).assert();

// Use a try/catch block to catch errors immediately as CLR exceptions in the job.
   try 
   { 
       //Construct and configure the service client by retrieving the X++ type for the service and using the AifUtil class/

         // Retrieve the X++ type for the Bing service client object. 
       clientType = CLRInterop::getType("BingSearch.ServiceReferences.BingV2ServiceReference.BingPortTypeClient"); 

         // Use the AifUtil class to create an instance of the service client object. 
       _client = AifUtil::CreateServiceClient(clientType); 

       // Create the search request. 
       request = new BingSearch.ServiceReferences.BingV2ServiceReference.SearchRequest(); 
       request.set_AppId(#AppId); 

       // Note the search request string is “Dynamics AX”
       request.set_Query("Dynamics AX"); 
       sourceTypes = new BingSearch.ServiceReferences.BingV2ServiceReference.SourceType[1](); 
       sourceTypes.SetValue(BingSearch.ServiceReferences.BingV2ServiceReference.SourceType::Web, 0); 
       request.set_Sources(sourceTypes);

       // Configure the response for output.
       response = _client.Search(request); 
       webResponse = response.get_Web(); 

       // Get the search results. 
       webResults = webResponse.get_Results(); 
       webResult = webResults.GetValue(0); 

       // Display the first result in the InfoLog. 
       integer = webResponse.get_Total(); 
       info(strFmt("%1 total web results.", integer)); 
       integer = webResults.get_Count(); 
       info(strFmt("%1 results in response.", integer)); 
       info(""); 
       info("First result:"); 
       string = webResult.get_Title(); 
       info(strFmt("Title: %1", string)); 
       string = webResult.get_Description(); 
       info(strFmt("Description: %1", string)); 
       string = webResult.get_Url(); 
       info(strFmt("Url: %1", string)); 
   } 
   // Catch any exceptions.
   catch(Exception::CLRError) 
   {
     // Handle the exception and display message in the InfoLog.
     ex = CLRInterop::getLastException(); 
     info(ex.ToString()); 
   } 
}

HOW TO RUN A REPORT FROM CONTROLLER CLASS IN MICROSOFT DYNAMICS AX : VIKAS MEHTA

HOW TO RUN A REPORT FROM CONTROLLER CLASS
 IN MICROSOFT DYNAMICS AX 

public static void main(Args _args)
{
    // Initializing the object for a controller class, in this case, the class named AssetListingController.
    SrsReportRunController controller = new AssetListingController();

    // Getting the properties of the called object (in this case AssetListing MenuItem)
    controller.parmArgs(_args);
    // Setting the Report name for the controller.
    controller.parmReportName(ssrsReportStr(AssetListing, Report));

    // Initiate the report execution.
    controller.startOperation();
}

HOW TO GET DAY OF THE WEEK IN MICROSOFT DYNAMICS AX

HOW TO GET DAY OF THE WEEK 
IN MICROSOFT DYNAMICS AX 
int sleep(int _duration)
Pauses the execution of the current thread for the specified number of milliseconds
static void sleepExample(Args _arg)
{
    int seconds = 10;
    int i;
    ;
    i = sleep(seconds*1000);  
    print "job slept for " + int2str(i/1000) + " seconds";
    pause;
}

HOW TO GET ENUM VALUE FROM ENUM AS STRING IN MICROSOFT DYNAMICS AX

HOW TO GET ENUM VALUE FROM ENUM AS STRING 
IN MICROSOFT DYNAMICS AX 

static void getEnumValueAsString()
{
    str i;
    i = enumLiteralStr(ABCEnum, "valueInABCEnum");
    print i;
    pause;
}

HOW TO ROUND A DECIMAL NUMBER IN MICROSOFT DYNAMICS AX

HOW TO ROUND A DECIMAL NUMBER IN MICROSOFT DYNAMICS AX 

real decRound(real figure, int decimals)
  • decRound(1234.6574,2); //Returns the value 1234.66.
  • decRound(1234.6574,0); //Returns the value 1235.
  • decRound(1234.6574,-2); //Returns the value 1200.
  • decRound(12345.6789,1) //Returns the value 12345.70.
  • decRound(12345.6789,-1) //Returns the value 12350.00.

HOW TO GET CURRENT DAY OF THE YEAR IN MICROSOFT DYNAMICS AX

HOW TO GET CURRENT DAY OF THE YEAR IN MICROSOFT DYNAMICS AX 
static void dayOfYrExample(Args _arg)
{
    date d = today();
    int i;
    ;
    i = dayOfYr(d);
    print "Today's day of the year is " + int2Str(i);
    pause;
} 

HOW TO CONVERT DATETIME TO STRING IN MICROSOFT DYNAMICS AX

HOW TO CONVERT DATETIME TO STRING IN
 MICROSOFT DYNAMICS AX 
static void jobTestDatetime2str( Args _args )
{
    utcdatetime utc2 = 1959-06-17T15:44:33;
    str s3;
    ;
    s3 = datetime2Str( utc2 );
    info( s3 );
}
Related Posts Plugin for WordPress, Blogger...