Saturday, July 7, 2018

Wednesday, July 4, 2018

Create simple dialog dynamics 365 Operations

Below code can be used as base to create dialog in Dynamics 365 Operations.

To Start with, create new project in either existing model or create new model and add a new Runnable class with name ppPurchDeliveryScheduleCreateDialog.

Copy code below and past into your class code area, this contains all the basic methods, which are required to override while extending RunBase class.

Modify logic of this dialog as per your requirement.

/// <summary>
/// The <c>ppPurchDeliveryScheduleCreate</c> class takes inputs from user and creates delivery schedule lines.
/// </summary>
/// <remarks>
/// Create delivery schedule lines.
/// </remarks>
public class ppPurchDeliveryScheduleCreateDialog extends RunBase
{
    // User Input fields
    DialogField     fieldNoOfLines;
    
    // Variables to store user input
    ppNumberOfLines numberOfLines;

    // pack() and unpack() methods are used to load the last value from user
    // for our simple example we are not going to use them.
    public container pack()
    {
        return conNull();
    }

    public boolean unpack(container packedClass)
    {
        return true;
    }

    // Dialog method to capture runtime user inputs for customer details
    public Object dialog()
    {
        Dialog dialog = super();

        // Set a title for dialog
        dialog.caption( 'Enter number of lines:');

        // Add a new field to Dialog
        fieldNoOfLines = dialog.addField(extendedTypeStr(ppNumberOfLines), 'No of lines:');

        return dialog;
    }

    // Retrieve values from Dialog
    public boolean getFromDialog()
    {
        numberOfLines = fieldNoOfLines.value();
        return super();
    }

    //write business logic.
    public void run()
    {
        //TODO: User numberOfLines variable to create delivery schedule.
    }

    public static void main(Args _args)
    {
        ppPurchDeliveryScheduleCreateDialog deliverySchedule = new ppPurchDeliveryScheduleCreateDialog();

        // Prompt the dialog, if user clicks in OK it returns true
        if (deliverySchedule.prompt())
        {
            deliverySchedule.run();
        }
    }

}

Saturday, June 23, 2018

Retrieve last approver name for any workflow

Below code can be used to retrieve last approver name for any workflow activated in Dynamics AX/ 365 Finance and operations.

 static void dtGetLastApproverName(Args _args)  
 {  
    WorkflowTrackingStatusTable workflowTrackingStatus;  
    WorkflowTrackingTable workflowTrackingTable;  
    WorkflowTrackingCommentTable workflowTrackingCommentTable;  
    UserInfo userInfo;  

    select firstFast RecId, User from workflowTrackingTable  
     order by RecId desc   
     join workflowTrackingCommentTable   
    where workflowTrackingCommentTable.WorkflowTrackingTable ==   
          workflowTrackingTable.RecId  
    join UserInfo where UserInfo.id == WorkflowTrackingTable.User  
    exists join workflowTrackingStatus  
    where workflowTrackingTable.WorkflowTrackingStatusTable ==   
    workflowTrackingStatus.RecId  
    && workflowTrackingStatus.ContextRecId == _salesRecId //PurchRecID  
    && workflowTrackingStatus.ContextTableId == tableNum(SalesTable) //SalesTable  
    && workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;  

    if (workflowTrackingTable.RecId > 0)  
    {  
      info(strFmt(“%1 – %2 “,userInfo.name, workflowTrackingCommentTable.RecId));  
    }  
 }  

Move SQL Server database files

Create tempdb partitions and move to new location location.

Know existing location:
SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('tempdb');

Move to new location:

ALTER DATABASE tempdb MODIFY FILE ( NAME = tempdev, FILENAME = "C:\SQLDB\tempdb.mdf")
ALTER DATABASE tempdb MODIFY FILE ( NAME = templog, FILENAME = "C:\SQLDB\templog.ldf")
ALTER DATABASE tempdb MODIFY FILE ( NAME = tempdev1, FILENAME = "C:\SQLDB\tempdb1.mdf")
ALTER DATABASE tempdb MODIFY FILE ( NAME = templog1, FILENAME = "C:\SQLDB\templog1.ldf")

Note:
Also verify that SQL service account has full access to new location.

To move msdb, need to follow steps below after executing above queries.

1. Go to SQL Server configuration manager.
2. Update path on parameters.


Friday, June 22, 2018

Verify active/enabled product dimension

Below code can be used to verify active or enabled specific or all product dimensions.

 
   public static void main(Args _args)
   {
     InventTable   inventTable;  
     InventDimParm  inventDimParm;  
     ;  

     inventTable  = InventTable::find('ABC');  

     inventDimParm = InventDimParm::activeDimFlag(InventDimGroupSetup::newInventTable(inventTable));  

     if(inventDimParm.InventColorIdFlag)  
     {  
       info("Color Enabled."); 
     }  
   }

Production picking list reservation through X++

Reserve without changing dimension.
 dtProdBOMReserve(Args _args)   
 {   
   prodJournalBOM prodJournalBOM;
   InventUpd_Reservation reservation;   
   ;   

   select * from prodJournalBOM    
    where prodJournalBOM.RecId == 5637695365;   

   movement = InventMovement::construct(prodJournalBOM);   
   reserveQuantity = prodJournalBOM.BOMConsump - abs(movement.transIdSum().reserved());  
   if(reserveQuantity)
   {
     reservation = InventUpd_Reservation::newMovement(movement,-reserveQuantity,true);   
     reservation.updateNow();  
   } 
   info('Reserved.');   
  }   

Reserve for specific dimension.


static void dtProdBOMReserveWithDim(Args _args)  
 {  
   prodJournalBOM prodJournalBOM;;  
   InventDim InventDim;  
   InventUpd_Reservation reservation;  
   ;  
   select * from prodJournalBOM  
     where prodJournalBOM.RecId == 5637695365;  

   //Update dimension
   inventDim = prodJournalBOM.inventDim();  
   inventDim.wMSLocationId = '12420301';  

   movement = InventMovement::construct(prodJournalBOM);  

   reserveQuantity = prodJournalBOM.BOMConsump - abs(movement.transIdSum().reserved()); 
 
   if(reserveQuantity)
   {
     reservation = InventUpd_Reservation::newInventDim(movement,inventDim, -reserveQuantity,false);  
     reservation.updateNow();  
   }

   info('Reserved.');  
 }  

Dynamics ax administration guide

1) Deploy all Reports using Dynamics AX Power shell. Publish-AXReport –ReportName * -id <AX Report server config name> 2) Delet...