Friday, September 9, 2022

Online store transaction new field flow to Sales order in D365FO

Set extension property for commerce order 

using Microsoft.Dynamics.Commerce.Runtime.Services.CustomerOrder;

using Microsoft.Dynamics.Commerce.Runtime.DataModel;

/// <summary>

/// Extension of <b>RetailTransactionTransformer</b> class

/// </summary>

[ExtensionOf(classStr(RetailTransactionTransformer))]

final class RetailTransactionTransformerCls_POL_Extension

{

/// <summary>

    /// Convert retail sales transaction into <b>ItemInfo</b> object

    /// </summary>

    public static ItemInfo ReadOneTransactionSalesTrans(RetailTransactionTable transactionTable, RetailTransactionSalesTrans salesTrans)

    {

        ItemInfo itemInfo = next ReadOneTransactionSalesTrans(transactionTable, salesTrans);

        ExtensionPropertyCollection extensionPropertyCollection = itemInfo.ExtensionProperties;

        CommerceProperty splitPropery = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionSalesTrans, <CustomField>), enum2int(salesTrans.<CustomField>));

        CommerceProperty comment            = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionSalesTrans, comment), salesTrans.comment);

        extensionPropertyCollection.Add(splitPropery );

        extensionPropertyCollection.Add(comment);

        return itemInfo;

    }


    /// <summary>

    /// This method is used to read sales transactions for return.

    /// </summary>

    public static ItemInfo ReadOneTransactionSalesTransForReturn(

                RetailTransactionTable transactionTable,

                RetailTransactionSalesTrans salesTrans)

    {

        ItemInfo itemInfo = next ReadOneTransactionSalesTransForReturn(transactionTable, salesTrans);


        ExtensionPropertyCollection extensionPropertyCollection = itemInfo.ExtensionProperties;


        CommerceProperty customLineNumber   = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionSalesTrans, customPortalLineNum), salesTrans.customPortalLineNum);        

        extensionPropertyCollection.Add(customLineNumber   );

        return itemInfo;

    }


    /// <summary>

    /// Convert a transaction data into customer order info.

    /// </summary>

    public static CustomerOrderInfo ConvertTransactionToCustomerOrderInfo(RetailTransactionTable transactionTable)

    {

        CustomerOrderInfo customerOrderInfo =  next ConvertTransactionToCustomerOrderInfo(transactionTable);

        var extensionPropertyCollection = customerOrderInfo.ExtensionProperties;

        CommerceProperty custPurchaseOrder  = new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionTable, CustPurchaseOrder), transactionTable.CustPurchaseOrder);

        CommerceProperty  isImport= new Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty(fieldStr(RetailTransactionTable, isImport), enum2Str(transactionTable.isImport));        

        extensionPropertyCollection.Add(custPurchaseOrder);

        extensionPropertyCollection.Add(isImport);

        return customerOrderInfo;

    }

}


using Microsoft.Dynamics.Commerce.Runtime.Services.CustomerOrder;

/// <summary>

    /// To update sales order while creating through sync orders from retail

    /// </summary>

    [SubscribesTo(classStr(RetailTransactionServiceOrders), staticDelegateStr(RetailTransactionServiceOrders, beforeCreatingRetailOrderLines))]

    public static void RetailTransactionServiceOrders_beforeCreatingRetailOrderLines(SalesTable _salesTable, Microsoft.Dynamics.Commerce.Runtime.Services.CustomerOrder.CustomerOrderInfo _customerOrderInfo)

    {

        var extensionPropertyCollection = _customerOrderInfo.ExtensionProperties;

        Microsoft.Dynamics.Commerce.Runtime.DataModel.CommercePropertyValue propertyValue;

        boolean                 update = false;

        for (int i=0; i < extensionPropertyCollection.get_Count(); i++)

        {

            var commerceProperty = extensionPropertyCollection.get_Item(i) as Microsoft.Dynamics.Commerce.Runtime.DataModel.CommerceProperty;

            switch(commerceProperty.Key)

            {

                case fieldStr(RetailTransactionTable, custPurchaseOrder):

                     propertyValue = commerceProperty.Value;

                    _salesTable.PurchOrderFormNum = propertyValue.StringValue;

                    update = true;

                    break;

                case fieldStr(RetailTransactionTable, <CustomField>): //Enum

                    propertyValue = commerceProperty.Value;

                    NoYesId noYesId;

                    _salesTable.<CustomField> = str2Enum(noYesId,propertyValue.StringValue);

                    update = true;

                    break;

                case fieldStr(RetailTransactionTable, <CustomField>):

                    propertyValue = commerceProperty.Value;

                     _salesTable.<CustomField>= propertyValue.StringValue;

                    break;

            }

             

        }

        if(update)

        {

            _salesTable.doUpdate();

        }

    }

Thursday, September 8, 2022

Power Automate (Flow) Expression usage samples


Get list items from Array

item()?['weborder']

Get compose output body content

outputs('Get_file_content')?['body']

Get Blob content

outputs('Get_blob_content_using_path_(V2)')?['body']

outputs('Get_blob_content_using_path_(V2)')?['value']


Split string by comma

split(variables('<var name>'),',')


Decode CSV file from Blob DECODE URI:

split(outputs('Get_blob_content_using_path_(V2)')?['body'], decodeUriComponent('%0D%0A'))

Skip output line 1

skip(outputs('splitNewLine'),2)

Get output value from list

outputs('OutputJSON')?['WebOrderNo']

outputs('D365FOSelectOut')?['body']

Find length of array

length(body('D365FOSelectOut'))

Concat string

concat(variables('OutputArrayResult'),outputs('D365FOSelectOut')?['body'])

Append array variables (Reference Blog) using Append to array variable (Action)

https://www.enjoysharepoint.com/power-automate-array-variable/

Get output Body/Value

outputs('Lists_items_present_in_table')?['body/value']

Date time format: (Reference Blog)
https://sharepains.com/2018/11/12/formatdatetime-power-automate/


Convert: (while using HTTP request output content type is octet stream, but excepted should be in Text/csv. Follow below

Header; Add in addition to existing header
"x-ms-access-tier-inferred": true

output:
{
"$content-type":  "application/octet-stream",
"$content":  "Ww0KICB7DQogICCJyZWNlaXZlciI6ICIgMTIzODUiLA0KICAgICJwYXlsb2FkIjogIiB7J21lc3NhZ2UnOiAndGVzdCAxJyIsDQogICAgIm9wZXJhdG9yIjogIiAnRW5naW5lSWQnOiAzIiwNCiAgICAic2VuZGVyIjogIiAnUGVyc29uSWQnOiAxIg0KICB9LA0KICB7DQogICAgImlkIjogIjIiLA0KICAgICJyZWNlaXZlciI6ICIgMTIzNDciLA0KICAgICJwYXlsb2FkIjogIiB7J21lc3NhZ2UnOiAndGVzdCAyJyIsDQogICAgIm9wZXJhdG9yIjogIiAnRW5naW5lSWQnOiAzIiwNCiAgICAic2VuZGVyIjogIiAnUGVyc29uSWQnOiAyIg0KICB9DQpd"
}

then we use

string(triggerBody()) ex: string(outputs('HTTPGetBlobContent')?['body'])

Date difference:
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),864000000000)
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),36000000000)
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),600000000)
div(sub(ticks({EndDateTime}),ticks({StartDateTime})),10000000)

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...