Monday, October 6, 2025

How to Control Edit Access for Sales Tax Fields in PR Lines Through Configuration in D365 Finance & Operations

 To provide a configuration-driven approach for controlling edit access to the Item Sales Tax Group and Sales Tax Group fields on Purchase Requisition (PR) lines.

When the toggle “Enable Tax Group configuration under PR lines” is enabled, users can edit these fields at specific PR workflow stages — in Draft and Finance Review states. When the toggle is disabled, editing is not allowed at any stage.

Configuration Steps:-
Navigation: Procurement and sourcing > Setup > Procurement and sourcing parameters > Configurations
Field: Purchase Requisition Line Sales Tax Group
Purpose: Controls whether users can edit the Item Sales Tax Group and Sales Tax Group fields on Purchase Requisition lines.
When Toggle Enabled (Yes): The Item Sales Tax Group and Sales Tax Group fields on PR lines are editable only when the PR status is Draft or Finance Review.

Code:-

[ExtensionOf(formDataSourceStr(PurchReqTable, PurchReqLine))]
internal final class PurchReqTable_PurchReqLine_Extension
{
    public int active()
    {
        FormDataSource  formDataSource = this as formDataSource;
        int ret = next active();

        PurchReqTable       purchreqTable;
        HcmWorker           hcmWorker;
        PurchReqLine        purchreqline = formDataSource.cursor();
        PurchParameters     purchParameters = PurchParameters::find();
        DirPersonUser       personUser;
        UserInfo            userInfo;
        str                 userId;
        UserGroupList       userGroupList;

        if (purchParameters.prlinesalestaxitemgroup == NoYes::Yes)
        {
            select purchreqTable
                where purchreqTable.RecId == purchreqline.purchReqTable;

            select hcmWorker
                where hcmWorker.RecId == purchreqline.Requisitioner;

            select personUser
                where personUser.PersonParty == hcmWorker.Person;

            select * from userInfo
                where userInfo.id == personUser.User;

            // Editable when PR is in Draft status and created by current user
            if (userInfo.id == curUserId() && purchreqTable.PurchReqStatus == "Draft")
            {
                formDataSource.allowEdit(true);
                formDataSource.object(fieldNum(PurchReqLine, TaxItemGroup)).enabled(true);
                formDataSource.object(fieldNum(PurchReqLine, TaxItemGroup)).allowEdit(true);
                formDataSource.object(fieldNum(PurchReqLine, TaxGroup)).enabled(true);
                formDataSource.object(fieldNum(PurchReqLine, TaxGroup)).allowEdit(true);
            }

            // For Finance Review stage
            WorkflowTrackingStatusTable workflowTrackingStatusTable;
            WorkflowWorkItemTable       workflowWorkItemTable;
            UserInfo                    userInfoloc;
            boolean                     isCurUser;

            FormTabPageControl tabItem                = this.formRun().design().controlName("tabItem") as FormTabPageControl;
            FormTabPageControl tabGeneralLine         = this.formRun().design().controlName("tabGeneralLine") as FormTabPageControl;
            FormTabPageControl tabProject             = this.formRun().design().controlName("tabProject") as FormTabPageControl;
            FormTabPageControl tabQuestionnaire       = this.formRun().design().controlName("tabQuestionnaire") as FormTabPageControl;
            FormTabPageControl tabFixedAsset          = this.formRun().design().controlName("tabFixedAsset") as FormTabPageControl;
            FormTabPageControl tabInventoryDimensions = this.formRun().design().controlName("tabInventoryDimensions") as FormTabPageControl;
            FormTabPageControl tabFinancialDimensions = this.formRun().design().controlName("tabFinancialDimensions") as FormTabPageControl;
            FormTabPageControl tabAddress             = this.formRun().design().controlName("tabAddress") as FormTabPageControl;

            if (purchreqTable.PurchReqStatus == "Finance Review")
            {
                while select workflowWorkItemTable
                    where workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem
                        && workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending
                    join workflowTrackingStatusTable
                        where workflowWorkItemTable.CorrelationId == workflowTrackingStatusTable.CorrelationId
                            && workflowTrackingStatusTable.ContextTableId == purchreqTable.TableId
                            && workflowTrackingStatusTable.ContextRecId == purchreqTable.RecId
                            && workflowTrackingStatusTable.TrackingStatus == WorkflowTrackingStatus::Pending
                    join userInfoloc
                        where workflowWorkItemTable.UserId == userInfoloc.id
                {
                    if (userInfoloc.id == curUserId())
                    {
                        isCurUser = true;
                        break;
                    }
                }

                if (isCurUser)
                {
                    formDataSource.allowEdit(true);
                    formDataSource.object(fieldNum(PurchReqLine, TaxItemGroup)).enabled(true);
                    formDataSource.object(fieldNum(PurchReqLine, TaxItemGroup)).allowEdit(true);
                    formDataSource.object(fieldNum(PurchReqLine, TaxGroup)).enabled(true);
                    formDataSource.object(fieldNum(PurchReqLine, TaxGroup)).allowEdit(true);

                    formDataSource.object(fieldNum(PurchReqLine, PurchPrice)).allowEdit(false);
                    formDataSource.object(fieldNum(PurchReqLine, CurrencyCode)).allowEdit(false);
                    formDataSource.object(fieldNum(PurchReqLine, IsPrepayment)).allowEdit(false);
                    formDataSource.object(fieldNum(PurchReqLine, LineComplete)).allowEdit(false);

                    tabItem.allowEdit(false);
                    tabGeneralLine.allowEdit(false);
                    tabProject.allowEdit(false);
                    tabQuestionnaire.allowEdit(false);
                    tabFixedAsset.allowEdit(false);
                    tabInventoryDimensions.allowEdit(false);
                    tabFinancialDimensions.allowEdit(false);
                    tabAddress.allowEdit(false);
                }
            }
        }

        return ret;
    }
}











No comments:

Post a Comment

How to Control Edit Access for Sales Tax Fields in PR Lines Through Configuration in D365 Finance & Operations

 To provide a configuration-driven approach for controlling edit access to the Item Sales Tax Group and Sales Tax Group fields on Purchase...