adsenseheader

Monday, November 14, 2022

Construct JSON and Webhook trigger from Dynamics 365 finance and operations through x++

DMFDefinitionGroupExecution     dmfDefGrpExec;
        DMFDefinitionGroup              dmfDefGrp;

        System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();

        while select forupdate dmfDefGrpExec
            join dmfDefGrp
            where dmfDefGrp.DefinitionGroupName == dmfDefGrpExec.DefinitionGroup
                && dmfDefGrp.TriggerWebHook
        {
            System.IO.StringWriter          stringWriter;
            Newtonsoft.Json.JsonTextWriter  jsonWriter;
 
            stringWriter       = new System.IO.StringWriter();
            jsonWriter         = new Newtonsoft.Json.JsonTextWriter(stringWriter);

            str sJSON = "";
            jsonWriter.WriteStartObject();
            jsonWriter.WritePropertyName("ExecutionId");
            jsonWriter.WriteValue(dmfDefGrpExec.ExecutionId);
            jsonWriter.WriteEndObject();

            sJSON = stringWriter.ToString();

            System.Net.Http.HttpContent content = new System.Net.Http.StringContent(sJSON,
                                                                        System.Text.Encoding::UTF8,
                                                                        "application/json");
            var task = httpClient.PostAsync("https://xxxxxxxxx-functionapp.azurewebsites.net/api/SyncStatus?code=5XBiPd0z_HCZpENuNAUabeXFAu5a-Lg7j_K5MWwOQpahAzFucoyn0w==",content);
            task.Wait();
            System.Net.Http.HttpResponseMessage msg = task.Result;
 
            System.Net.Http.HttpContent ct = msg.Content;
            var result = ct.ReadAsStringAsync();
            result.Wait();
            System.String s = result.Result;

            mapEnumerator   mapEnumerator;
            Map             data;

            data = RetailCommonWebAPI::getMapFromJsonString(s);
            mapEnumerator = data.getEnumerator();
            while (mapEnumerator.moveNext())
            {
                if (mapEnumerator.currentKey() == "message")
                {
                    ttsbegin;
                    dmfDefGrpExec.Status = mapEnumerator.currentValue();
                    dmfDefGrpExec.doUpdate();
                    ttscommit;
                }
            }
        }

Thursday, October 20, 2022

Link Purchase order and Sales order through Marking in x++ D365 FO

Public void LinkPOAndSO(InventTransId _poTransid InventTransId _soTransId Qty _qtyToMark)
{
tmpInventTransMark tmpInventTransMark;
InventTransId issueInventTransId = _poTransid;
InventTransId receiptInventTransId = _soTransId;
InventTransOriginId receiptInventTransOriginId =
InventTransOrigin::findByInventTransId(receiptInventTransId).RecId;
InventTrans receiptInventTrans =
InventTrans::findByInventTransOrigin(receiptInventTransOriginId);
InventTransOriginId issueInventTransOriginId =
InventTransOrigin::findByInventTransId(issueInventTransId).RecId;
InventTrans issueInventTrans =
InventTrans::findByInventTransOrigin(issueInventTransOriginId);
MarkingCollection collection = TmpInventTransMark::markingCollection(
InventTransOrigin::find(receiptInventTransOriginId)
receiptInventTrans.inventDim()
receiptInventTrans.Qty);
collection.insertCollectionToTmpTable(tmpInventTransMark);
select firstonly tmpInventTransMark
where tmpInventTransMark.InventTransOrigin == issueInventTrans.InventTransOrigin
&& tmpInventTransMark.InventDimId == issueInventTrans.InventDimId;
if (tmpInventTransMark.RecId != 0)
{
Qty qtyToMark;
if (_qtyToMark)
{
qtyToMark = _qtyToMark;
}
else
{
qtyToMark = issueInventTrans.Qty;
}
tmpInventTransMark.QtyMarkNow = qtyToMark;
tmpInventTransMark.QtyRemain -= tmpInventTransMark.QtyMarkNow;
Map mapUpdated = new Map(Types::Int64 Types::Record);
mapUpdated.insert(tmpInventTransMark.RecId tmpInventTransMark);
TmpInventTransMark::updateTmpMark(
receiptInventTransOriginId
receiptInventTrans.inventDim()
-qtyToMark
mapUpdated.pack());
}
}

Tuesday, May 10, 2022

Computed columns on extended data entites in D365 FO

HI,

If you are wondering how to write computed column in entity extension below is the sample piece of code.

Step 1: Create a class object extends your entity
Step 2: Sample code to get ISO code from LogisticsAddressCountryRegion

[ExtensionOf(tableStr(LogisticsAddressCountryRegionTranslationEntity))]
public final class LogisticsAddressCountryRegionTranslation_DIS_Extension {
    public static server str ISOCode_DIS() {
        SysDictTable dictLogisticsCountryRegion = new SysDictTable(tableNum(LogisticsAddressCountryRegion));
        LogisticsAddressCountryRegion logisticsAddressCountryRegion;

        str countryRegionID = SysComputedColumn::returnField(dataentityviewstr(LogisticsAddressCountryRegionTranslationEntity), identifierstr(LogisticsAddressCountryRegionTranslation), fieldstr(LogisticsAddressCountryRegionTranslation, CountryRegionId));

        str val = strFmt("SELECT TOP 1 %1 FROM %2 WHERE %2.%3 = %4",
            dictLogisticsCountryRegion.fieldName(fieldNum(LogisticsAddressCountryRegion, ISOcode), DbBackend::Sql),
            dictLogisticsCountryRegion.name(DbBackend::Sql),
            dictLogisticsCountryRegion.fieldName(fieldNum(LogisticsAddressCountryRegion, CountryRegionId), DbBackend::Sql),
            countryRegionID);

        return val;
    }

}


Step 3: Create a unmapped field(required type) in my
case its STR.In the property DataEntityViewMethod "LogisticsAddressCountryRegionTranslation_DIS_Extension::ISOCode_DIS"

Stpe 4: Create a field in Staging table
Step 5: Compile and Synchronise the created objects.

Regards,
Pradeep

Tuesday, January 18, 2022

Copy Data From One Table To Another Table By Using buf2buf- D365FO

Hello Guys...! Some times we get requirement like , we have to copy data from one table to other table . For that we created a new static method. This method we can use if our second table fields Id's are same as First table field Id's. Here in the example we are copying data from Staging table to Target table.
static void buf2Buf(Common  _from,
                                Common  _to,
                                TableScope _scope = TableScope::CurrentTableOnly)
    {
        var         dictTable = new DictTable(_to.TableId);
        int64       tableId;
        FieldId     fieldId = dictTable.fieldNext(0, _scope);

        while (fieldId && ! isSysId(fieldId))
        {
            _to.(fieldId)   = _from.(fieldName2Id(_from.tableId,fieldId2Name(_to.tableId,fieldId)));
            fieldId         = dictTable.fieldNext(fieldId, _scope);
        }
    } 

Tuesday, December 21, 2021

Delete or remove customer delivery address in D365 FO

while select custTable
               where   !custTable.Blocked
                    join RecId from dirPartyTable
               where   dirPartyTable.RecId == custTable.Party
                    join RecId from dirPartyLocation
               where   dirPartyLocation.Party == custTable.Party
                    join RecId from dirPartyLocationRole
               where   dirPartyLocationRole.PartyLocation == dirPartyLocation.RecId
                   join RecId from logisticsLocationRole
               where   logisticsLocationRole.RecId == dirPartyLocationRole.LocationRole
                          && logisticsLocationRole.Type == LogisticsLocationRoleType::Delivery
                    join RecId from logisticsLocation
                where   logisticsLocation.RecId == dirPartyLocation.Location
                    join forupdate logisticsPostalAddress
                where   logisticsPostalAddress.Location == logisticsLocation.RecId 
            {
                ttsbegin;
                logisticsPostalAddress.deactivate(custTable);
                ttscommit;
            }

Saturday, April 4, 2020

Get packing slip id for the Posted Invoice in Dynamics AX

Hi Guys,

If you are looking for code that needs to find a Packing slip Id for the posted Customer Invoice in Dynamics AX 365 for operations.

Below is the code that helps you out!


static void getPackingSlip(Args _args)
{
    CustInvoiceJour     custInvoiceJour;
    SalesParmTable      salesParmTable;
    CustPackingSlipJour custPackingSlipJour;
    SalesParmSubLine    salesParmSubLine;
    SalesParmLine       salesParmLine;

    custInvoiceJour = CustInvoiceJour::findRecId(35637193385);
    select firstOnly salesParmTable
        where salesParmTable.ParmId == custInvoiceJour.ParmId
            && salesParmTable.Ordering == DocumentStatus::Invoice;

    //in case of mulitple packing slip selected in invoice
    while select DocumentId from salesParmSubLine
            exists join salesParmLine
            where salesParmSubLine.LineRefRecId == salesParmLine.RecId
                && salesParmLine.ParmId          == salesParmTable.ParmId
                && salesParmLine.TableRefId      == salesParmTable.TableRefId
    {
        select firstOnly custPackingSlipJour
            where custPackingSlipJour.PackingSlipId == salesParmSubLine.DocumentId
                && custPackingSlipJour.SalesId == salesParmTable.SalesId;
        info(strFmt("%1-%2-%3-%4",custPackingSlipJour.DeliveryDate,custPackingSlipJour.PackingSlipId,salesParmTable.SalesId,custInvoiceJour.InvoiceId));
    }
}

Thursday, April 2, 2020

Post Partial Purchase Order Lines through Code in AX 365 for opeartions

Hi Guys,

The below code shall help you to post the Purchase order line level Product receipt posting. Basically, its a partial Product receipt posting.

     public static void main(Args _args)
    {

                   Query        query;
                   SysQueryRun        queryRun;
                   QueryBuildDataSource qbds;


                      ttsbegin;
select firstonly1 purchLinePost
                        where purchLinePost.InventTransId == "xxxxx";

    query = new Query(QueryStr(PurchUpdatePackingSlip));
                    qbds = query.dataSourceTable(tableNum(PurchLine));
                    qbds.addRange(fieldNum(PurchLine, RecId)).value(queryValue(purchLinePost.RecId));
                    queryRun = new SysqueryRun(query);

                    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
                    purchFormLetter.chooseLinesQuery(queryRun);
                    purchFormLetter.update(icPurchTable,icPurchTable.PurchId);
                    ttscommit;
      }

Note: Use SysQueryRun object instead of QueryRun.

Happy Daxing!!

Regards,
Pradeep