Saturday, June 11, 2022

How to get a specific display value from defaultdimension using X++ code

   public static Str  GetProject(DimensionDefault _DimensionDefault)

    {

        DimensionAttributeValueSet           DimensionAttributeValueSet;

        DimensionAttributeValueSetItem    DimensionAttributeValueSetItem;

        DimensionAttributeValue                DimensionAttributeValue;

        DimensionAttribute                         DimensionAttribute;

        DimensionAttributeValueSetStorage           dimStorage;

        Str                     Project;

        Counter i;

     dimStorage = DimensionAttributeValueSetStorage::find(_DimensionDefault);

        for (i=1 ; i<= dimStorage.elements() ; i++)

        {

            // Change the string "CostCenter" to any financial dimension

            if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name =="CostCenter")

            {

 Project=dimStorage.getDisplayValueByIndex(i);

  select firstonly DimensionAttributeValueSetItem where                           DimensionAttributeValueSetItem.DisplayValue==Project;

            }        

     }

        return DimensionAttributeValueSetItem.DisplayValue;

    }

Thursday, March 31, 2022

How to make Unit Price(PurchPrice) editable in Purchase requisition lines in Dynamics 365 for finance and operations

 The only way to make it possible is by extending the purchreqline table method and using Chain of Command(CoC)

The following code will make you achieve the task:
[ExtensionOf(tablestr(PurchReqLine))]
final class PurchReqLine_Extension
{
    public boolean allowFieldEdit(FieldId _fieldId, boolean _isUserTaskApprovalOwner )
    {
        boolean   allowEdit= false;
        allowEdit  = next  allowFieldEdit(_fieldId,_isUserTaskApprovalOwner);
   {
            if (_isUserTaskApprovalOwner && (this.RequisitionStatus == PurchReqRequisitionStatus::Draft ||
                                         this.RequisitionStatus == PurchReqRequisitionStatus::InReview ||
                                         this.RequisitionStatus == PurchReqRequisitionStatus::Rejected))
            {
                switch (_fieldId)
                {
                    case fieldNum(PurchReqLine,PurchPrice):
                    if (this.LineType == PurchReqLineType::Item || this.LineType == PurchReqLineType::Category)
                        {
                            allowEdit = true;
                        }
     break;
case fieldNum(PurchReqLine, PurchQty):
                    if (this.LineType == PurchReqLineType::Item || this.LineType == PurchReqLineType::Category)
                        {
                            allowEdit = true;
                        }
                        break;
                    case fieldNum(PurchReqLine, LineAmount):
                    if (this.LineType == PurchReqLineType::Item || this.LineType == PurchReqLineType::Category)
                        {
                            allowEdit = false;
                        }
                        break;
                }
            }
        }
        Return allowEdit;
    }
}
Note:I have added code to ensure that the quantity(PurchQty) field remains editable and the net amount 
field(LineAmount) is not editable.