Friday 17 May 2019

How to get form datasource object in an Eventhandler in Dynamics 365 Finance X++

In this example I'll be showing you how to get a data-source in the event-handler for form method 'closeok'. In this example I'm using post event.

You can change the code for other form methods in the same way.

class SalesEditLines_EventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(formStr(SalesEditLines), formMethodStr(SalesEditLines, closeOk))]
    public static void SalesEditLines_Post_closeOk(XppPrePostArgs args)
    {
        FormRun sender = args.getThis();
        SalesParmUpdate salesParmUpdate;
        salesParmUpdate = sender.dataSource(formdatasourcestr(SalesEditLines, SalesParmUpdate)).cursor();

        info(salesParmUpdate.ParmId);
    }

}

Monday 13 May 2019

How to get workflow submitted userID and Datetime in D365 Finance & Operations x++

In this post I'll be sharing a job to get purchase order workflow submitted userID and datetime.

Change the logic according to your requirement.


class WorkflowUserDatetime
{     
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        WorkflowTrackingTable workflowTrackingTable;
        WorkflowTrackingStatusTable workflowTrackingStatusTable;
        WorkflowTrackingCommentTable    workflowTrackingCommentTable;
        PurchTable  purchTable = PurchTable::find('POV002357'); // Change the table name


        select firstFast RecId, User,CreatedDateTime from workflowTrackingTable
            order by RecId desc
            join workflowTrackingCommentTable
            where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
            exists join workflowTrackingStatusTable
            where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
            && workflowTrackingStatusTable.ContextRecId == purchTable.RecId // Change table recid
            && workflowTrackingStatusTable.ContextTableId == purchTable.TableId // Change table ID
            && workflowTrackingTable.TrackingType == WorkflowTrackingType::Submission;// Change the enum value to approval to get approved user details

        if (workflowTrackingTable.RecId > 0)
        {
            Info(strFmt("%1 - %2", workflowTrackingTable.CreatedDateTime , workflowTrackingTable. User));
        }
    }

}

@Rahul

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...