Thursday, July 18, 2024

Label D365FO cloud environments using extensions

In D365FO Developers, Testers, key users, functional consultants will work on multiple environments. It is very important to them to differentiate and which environments they are working on.

Using below Extensions, you can enter the URL of specific cloud environments, for example to separate PROD environments from TEST environments like in the attached image.

Chrome: https://chromewebstore.google.com/detail/environment-marker/ahjhdebcnlgmojdmjnhikhakkghcchkk

Edge: https://microsoftedge.microsoft.com/addons/detail/environment-marker/iggchogopggbmjgplniemfaghmdkhlip






Wednesday, July 3, 2024

Copy args value to variable

CopyArgs() method will copy args value from one args to another variable 


 private void run(Args _args)

{

    Args salesArgs  = Args::copyArgs(_args, new Args());

    Args projArgs   = Args::copyArgs(salesArgs, new Args());

    Map  dataSourceValidRecs = new Map(extendedTypeId2Type(extendedTypeNum(RecId)), Types::Record);

    

    if (FormDataUtil::getFormDataSource(salesArgs.record()))

    {

        FormDataSource formDataSource_ds = FormDataUtil::getFormDataSource(salesArgs.record());


        for (Common common = formDataSource_ds.getFirst(true) ? formDataSource_ds.getFirst(true) : formDataSource_ds.cursor();

            common;

            common = formDataSource_ds.getNext())

        {

            WHSPostPackingSlipAction postPackingSlipAction = this.constructPostPackingSlipAction(common, salesArgs);


            if (postPackingSlipAction.validateCanPackingSlipBePosted())

            {

                this.determinePackingSlipTypes(postPackingSlipAction.whsPackingSlipType());


                dataSourceValidRecs.insert(common.RecId, common);

            }

        }

    }

}

Monday, June 24, 2024

Check Security Privilege is assigned or not for that User iusing X++

 

Below method will help to check security Privileges assigned for that user.

public static boolean hasUserSecurityPrivilege(SecurityPrivilegeName _securityPrivilege, UserId _userId = curUserId())

{

  SecurityRolePrivilegeExplodedGraph securityRolePrivilegeExplodedGraph;

  SecurityUserRole securityUserRole;

  SecurityPrivilege securityPrivilege;

  select firstonly securityPrivilege

    where securityPrivilege.Identifier == _securityPrivilege

  exists join securityRolePrivilegeExplodedGraph

    where securityRolePrivilegeExplodedGraph.SecurityPrivilege == securityPrivilege.RecId

  exists join securityUserRole

    where securityUserRole.SecurityRole == securityRolePrivilegeExplodedGraph.SecurityRole

       && securityUserRole.User == _userId

       && securityUserRole.AssignmentStatus == RoleAssignmentStatus::Enabled

       && (securityUserRole.ValidFrom < DateTimeUtil::utcNow() || securityUserRole.ValidFrom == utcDateTimeNull())

       && (securityUserRole.ValidTo > DateTimeUtil::utcNow() || securityUserRole.ValidTo == utcDateTimeNull());

  return securityPrivilege.RecId != 0;

}


Orelse you can use below method also with dummy control in form

Logic to implement user has specific privilege through code:

Created one dummy form control with visibility false and need permission manual and created privilege using below logic we can verify the access.

SecurityRights securityRights = SecurityRights::construct();

        maxAccess = securityRights.formControlAccessRight(formStr(SalesTable), formControlStr(SalesTable, QTQSalesStatus));

=============

verify user has specific role assigned or not.

if (xUserInfo::checkUserRole(roleStr(InventMaterialsManager))

            || xUserInfo::checkUserRole(roleStr(InventQualityControlManager)) 

            || xUserInfo::checkUserRole(roleStr(WMSWarehouseManager)) 

            || Global::isSystemAdministrator())