web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Conditionally not allow a field to be edited when record is created

(0) ShareShare
ReportReport
Posted on by 110

When creating a sales order and adding lines to the order, I'd like to set our Sales Price field to not be editable based on certain criteria.  I have a solution in place to not edit that field after it's been created, but I need a solution for users to not edit that field while it's being created.  Here's what I've done so far to the form SalesTable......

  • Set the AutoDeclaration property to Yes on the grid's SalesPrice object.
  • Created a form method with the following code:

void FJEdisableSalesPriceEdit()
{
    str modelGroupId;
    str itemId;


    itemId = SalesLine.ItemId;
    modelGroupId = inventModelGroupItem::modelGroupId(ItemId,'fje');

    if (modelGroupId == 'Std Cost')
    {
        salesLine_ds.object(fieldNum(SalesLine,SalesPrice)).allowEdit(false);
    }
    else
    {

        salesLine_ds.object(fieldNum(SalesLine,SalesPrice)).allowEdit(true);

    }
    salesLine_ds.refresh();
}

  • There was already an Active override method created previously in the SalesLine data source.  I added the following line of code to it just before return ret;

element.FJEdisableSalesPriceEdit();

 

Again, this works fine after I've created the line, then go back to edit it.  I just need it to work when created it.  I can't set the AllowEditOnCreate property to No on the SalesPrice field of the SalesLine table.  Is there a way I can conditionally set this property in X++ using similar syntax from above?  Thank you in advance for your help.


Travis


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi Travis

    Try overriding the "create" method on the data source or "initValue" methods on the datasource to accomplish this.

  • Suggested answer
    jasman Profile Picture
    1,413 on at

    Hi Travis.

    Firstly IMHO it is not recommended to hard code something like:

     if (modelGroupId == 'Std Cost')

    I would recommend you add a field to the invent model table that implements a checkmark that indicates if the field in question should be editable or not.
    Let's say that you add a field called SalesPriceEditAllowed of (EDT) type NoYesId.

    Then you could write something like:

    salesLine_ds.object(fieldNum(SalesLine,SalesPrice)).allowEdit(inventModelGroupItem::modelGroupId(ItemId,'fje').SalesPriceEditAllowed);

    Secondly you could try to set the AllowEdit property of the field in question to No on the DATASOURCE of the form. This way it the fields should initially be locked for editing, and the code above would unlock it if it necessary.

  • Suggested answer
    tkilmer76 Profile Picture
    110 on at

    Greetings gentlemen.  I apologize for just now getting back to you.  I never mentioned in my original post that I want the Sales Price field to be non-editable based on a certain category that the part number falls in.

    I attempted adding the element.FJEdisableSalesPriceEdit(); to the initValue method, but it did not work.  I set debugger breakpoints to step through the code and discovered that the initValue method runs as soon as you click the 'Add line' button on the sales order.  By the time I select a part number, the code has already ran and will not affect the SalesPrice field when selecting the part numbers.  What I ended up doing was I added the element.FJEdisableSalesPriceEdit(); line to the itemIdModified method of the SalesLine DS of the SalesTable form.  I still have all of the original code in place that I posted originally.  Jacob, I will change the modelGroupId statement to not contain a static value as I did in my original example.

    Thank you both for your help

    Travis

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans