Thursday, September 18, 2025

change lookup for documenttype in file upload from leave request

 Scenario:- Today in this blog we see how to alter lookup of document type based on document type in leave request form as shown in image below


 >>To get lookup of all document types write this logic

[ExtensionOf(classstr(DocuUpload))]
internal final class docucoc_Extension
{
    public DocuManagementOptions parmDocuMgmtOptions(DocuManagementOptions _value )
    {
        DocuManagementOptions docuMgmtOptions = next parmDocuMgmtOptions(_value);
        int num=this.currentTableId();
        if(tableId2Name(num)=="LeaveRequest")
        {this.setupDocuTypescoc();}
        return docuMgmtOptions;
    }

 

    public  void setupDocuTypescoc()
    {
        List            docuTypeList;
        ListIterator    docuTypeListIterator;
        ComboBoxItem    comboxBoxItem;

 

        // Get the list of document types for the primary table
        docuTypeList = DocuUpload::getDocuTypeListcoc();

 

        // Set the list of document types
        this.documentTypes(docuTypeList);

 

        // Initialize the iterator for the list of document types
        docuTypeListIterator = new ListIterator(docuTypeList);

 

        // If the iterator has at least one item, set the selected document type to the first element;
        // otherwise set the selected document to an empty string
        if (docuTypeListIterator.more())
        {
            comboxBoxItem = docuTypeListIterator.value();
            this.selectedDocumentType(comboxBoxItem.parmValue());
        }
        else
        {
            this.selectedDocumentType('');
        }
    }

 

    private static List getDocuTypeListcoc()
    {
        DocuType        docType;
        List            docuTypeList = new List(Types::Class);
        UserInfo        userInfo;

 

        // Get the current language
        select language from userInfo
            where UserInfo.id == curUserId();

 

        // Add all document types that aren't a document library
        while select @TypeId,ActionClassId from docType
            //index TypeIdx
            //where docType.ActionClassId == classNum(DocuActionArchive)
        {
            // If the document type isn't valid, just continue to the next element instead of adding it
            if (DocuEvent::doCheckSkipDocuType(docType))
            {
                continue;
            }

 

            docuTypeList.addEnd(new ComboBoxItem(docType.TypeId, docType.TypeId));
        }

 

        return docuTypeList;
    }

 

}

 

 





Wednesday, September 3, 2025

Filtering records in grid in datasource init method

 This article is about filtering records in grid

>> Generally if it comes to  Filtering records we go for execute query but sometime we see this not that appropriate working so  we go for formdatasource init


code:-

[ExtensionOf(FormDataSourcestr(PurchReqCopyRFQ,PurchReqLine))]
internal final class PurchReqCopyRFQ_Extension
{
    public void init()
    {
        next init();
        QueryBuildRange qbrBuyingLegalEntity;

        FormDataSource          purchReqLine_ds;

       purchReqLine_ds =this as FormDataSource;
       purchReqLine_ds.query().dataSourceTable(tableNum(PurchReqLine)).clearRanges();

        qbrBuyingLegalEntity = this.query().dataSourceTable(tableNum(PurchReqLine)).addRange(fieldNum(PurchReqLine, BuyingLegalEntity));

        qbrBuyingLegalEntity.value(queryValue(CompanyInfo::findDataArea(curExt()).RecId));
        qbrBuyingLegalEntity.status(RangeStatus::Locked);
    }

 

}

Tuesday, September 2, 2025

To get Country region shot name based on legal entity

 LogisticsAddressCountryRegionTranslation::find(LogisticsAddressCountryRegion::findByISOCode(SysCountryRegionCode::countryInfo(curext())).CountryRegionId).ShortName

Custom services in d365fo

 In this blog we see how to develop custom services in d365fo Mainly we need to develop 1) Request class 2) Response class  3) service class...