hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Thursday, August 31, 2023

Legal entity multiselect lookup in D365FO X++

 Legal entity multiselect lookup in D365FO X++ 

public void lookup()
{
   // super();
   Query       query               = new Query();
   TableId     multiSelectTableNum = tableNum(DataArea);
   container   selectedFields = [multiSelectTableNum, fieldName2id(multiSelectTableNum, fieldStr(DataArea, id))];
   query.addDataSource(tableNum(DataArea));
   query.dataSourceTable(tableNum(DataArea)).addSelectionField(fieldNum(DataArea,id));
   query.dataSourceTable(tableNum(DataArea)).addSelectionField(fieldNum(DataArea,Name));
   SysLookupMultiSelectGrid::lookup(query, this,this,this,selectedFields);
}
Query       query               = new Query();
TableId     multiSelectTableNum = tableNum(DataArea);
container   selectedFields = [multiSelectTableNum, fieldName2id(multiSelectTableNum, fieldStr(DataArea, id))];
query.addDataSource(tableNum(DataArea));
query.dataSourceTable(tableNum(DataArea)).addSelectionField(fieldNum(DataArea,id));
query.dataSourceTable(tableNum(DataArea)).addSelectionField(fieldNum(DataArea,Name));

ctrl = SysLookupMultiSelectCtrl::constructWithQuery(this.formRun(),
								this,
								query,
								false,
								selectedFields);

container con = ctrl.GetselectedFieldValues();


Thanks for reading!!

Friday, August 25, 2023

X++ code to get Derived dimension

 X++ code to get Derived dimension

public static str derivedDim(str _dimAttrName,str _dimValue)
{
    //_dimAttrName   Base dimension
    // _dimValue     Base dimension value
    DimensionAttributeValueDerivedDimensions derivedDim;
    DimensionAttribute          dimAttribute;
    DimensionAttributeValue     dimAttriValue;
    str                         derivedDimValue;
    dimAttribute = DimensionAttribute::findByName(_dimAttrName);
    if(dimAttribue)
    {
	dimAttriValue   = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute,_dimValue);
	derivedDim      = DimensionAttributeValueDerivedDimensions::findByDimensionAttributeValue(dimAttribute.RecId,dimAttriValue.RecId);
	dimAttriValue   = DimensionAttributeValue::find(derivedDim.DerivedDimensionAttributeValue1);

	select firstonly derivedDim where derivedDim.DimensionAttribute == dimAttribute.RecId;
	dimAttribute = DimensionAttribute::find(derivedDim.DimensionAttribute);

	if(dimAttribute)
	{
	   derivedDimValue = dimAttriValue.DisplayValue;
	}
	
    }
    return derivedDimValue;
}

Thanks for reading!!

Thursday, August 24, 2023

Financial dimension lookup

 

Financial dimension lookup Code X++.

public static void lookupControl(FormControl _formControl, str _value)
{
	FormStringControl   control;
	Args                args;
	FormRun             formRun;
	DimensionAttribute  dimAttribute;
	dimAttribute    =   DimensionAttribute::findByName(_value);

	args            =   new Args();
	args.record(dimAttribute);
	args.caller(_formControl);
	args.name(formStr(DimensionLookup));

	formRun         =   classFactory.formRunClass(args);
	formRun.init();
	control         =   _formControl as FormStringControl;
	control.performFormLookup(formRun);
}

Friday, August 4, 2023

Inclusion of Bank Details During Copying Vendor From one LE to Other

Standard functionality allows for copying vendors from one legal entity (LE) to another, but it doesn't include the transfer of bank details. To enhance this, we have customized the vendor copying process to seamlessly incorporate the bank details functionality.

Please find the below code for the same.

[ExtensionOf(classStr(CustVendCopyDataUtil))]
final static class CustVendCopyDataUtil_Extension
{
   //Copy of bank details from one LE to other when copying the vendors 
    protected static void copyVendFormDataSources(VendTable sourceVendor, FormRun vendTableForm, Set datasourceSet, boolean needCreate)
    {
        FormDataSource  vendTable_ds;
        VendTable       vendTableLoc;
        next copyVendFormDataSources(_sourceVendor,_vendTableForm,_datasourceSet,_needCreate);
        vendTable_ds = _vendTableForm.dataSource(formDataSourceStr(VendTable, VendTable)) as FormDataSource;
        vendTableLoc = vendTable_ds.cursor();
        CustVendCopyDataUtil::CopyBankDetailsofVendor(_sourceVendor,vendTableLoc.AccountNum);
    }

    protected static void copyVendTableForVendor(VendTable sourceVendor, FormRun vendTableForm, Set datasourceSet)
    {
        FormDataSource  vendTable_ds;
        VendTable       vendTableLoc;
        next copyVendTableForVendor(_sourceVendor,_vendTableForm,datasourceSet);
        vendTable_ds = _vendTableForm.dataSource(formDataSourceStr(VendTable, VendTable)) as FormDataSource;
        vendTableLoc = vendTable_ds.cursor();
        buf2Buf(_sourceVendor, vendTableLoc);
        vendTable_ds.cursor().data(vendTableLoc);
        datasourceSet.add(vendTable_ds);
    }

    static void CopyBankDetailsofVendor(VendTable vendorTable,VendAccount accountNum)
    {
        VendTable   vendtable;
        VendBankAccount vendBankAccount, vendBankAccountLoc;
        while select  crosscompany * from vendBankAccountLoc
            where vendBankAccountLoc.VendAccount == _vendorTable.AccountNum
                && vendBankAccountLoc.DataAreaId == _vendorTable.DataAreaId
        {
            select vendBankAccount
                where vendBankAccount.VendAccount == vendBankAccountLoc.VendAccount
                    && vendBankAccount.AccountID == vendBankAccountLoc.AccountID;

            if (!vendBankAccount.VendAccount)
            {
                ttsbegin;
                buf2Buf(vendBankAccountLoc, vendBankAccount);
                vendBankAccount.VendAccount = _accountNum;
                vendBankAccount.insert();
                ttscommit;
            }
        }
    }
}

Thanks for reading my blog.

Keep Learning!!

Tables involved while opening the voucher transactions from purchase order receipts

 

 1. GeneralJournalAccountEntry

  2. GeneralJournalEntry

  3. SubledgerVoucherGeneralJournalEntry

  4. VendPackingSlipVersion

  5. VendPackingSlipJour

select generalJournalAccountEntry
join SubledgerVoucher,AccountingDate from generalJournalEntry          
where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
	&& generalJournalEntry.DocumentNumber == _VendPackingSlipJour.packingSlipId
	&& generalJournalEntry.AccountingDate == _VendPackingSlipJour.DeliveryDate
	&& generalJournalEntry.SubledgerVoucherDataAreaId == _VendPackingSlipJour.dataAreaId
exists join subledgerVoucherGeneralJournalEntry
   where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry == generalJournalEntry.RecId
exists join VendPackingSlipVersion 
   where VendPackingSlipVersion.AccountingDate == subledgerVoucherGeneralJournalEntry.AccountingDate
  && VendPackingSlipVersion.LedgerVoucher == subledgerVoucherGeneralJournalEntry.Voucher
    && VendPackingSlipVersion.VendPackingSlipJour == VendPackingSlipJour.Recid;
		


Keep Learning!!