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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Field shows a value on the form although a custom code empties it

(0) ShareShare
ReportReport
Posted on by 48

I created some custom code on the PurchReqLine table to empty the Requisitioner field on creation. 

I coded something like this : 

[ExtensionOf(tableStr(PurchReqLine))]
final class PurchReqLine_Table_Custom_Extension
{
    public void initFromPurchReqTable(PurchReqTable _purchReqTable)
    {
        next initFromPurchReqTable(_purchReqTable);

        this.Requisitioner = 0;
    }

}

The problem is that the field in the form PurchReqTable still shows a value for this field although it really is empty (I checked the record values). 

I tried to search for a way to empty a form control but it seems that the text() method is not recommended (and it doesn't work anyway). 

Does anyone have an idea for this problem ? 

Thanks

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Field shows a value on the form although a custom code empties it

    Hi Aleksandre,

    If Requisitioner field was empty before initFromPurchReqTable was called, and it's empty after that (because of your code), then it should definetely not show up on the form.

    So most likely the reason why it shows on the form is somewhere else, and you need to find this reason.

    For example, if you look at initValue method of PurchReqLine data source on the PurchReqTable form, you will notice that Requisitoner value is set there. Perhaps this explains it?

  • Alexandre Sarazin Profile Picture
    48 on at
    RE: Field shows a value on the form although a custom code empties it

    Hi Nikolaos,

    The Requisitioner field isn't empty before my code. And my code actually empties it.

    The initValue on the datasource is called but my code is called after that.

    I know it works because I see the empty field in the record info and if I try to save my line without updating the field, I get the error "Field 'Requester' must be filled in".

    My problem is with the control form. It shows the original value although it shouldn't show anything. There is something that prevents the control form from updating but I can't find the reason. And I don't know how to force it...

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Field shows a value on the form although a custom code empties it

    Where is the value being populated? Please share more details with us.

    Anyway I think that your current code is in the wrong place. You put it in a place where PurchReqLine values are initialized from PurchReqTable. But seems that you try to do something else. And also this code might be called in many other processes than just when purch requisition is created on this form.

    Generally you can always refresh the form data source to update values that are shown on the form. But it can only work if this record is already saved (=exists in the database). Based on your description, I don't know if it is saved or not.

  • Alexandre Sarazin Profile Picture
    48 on at
    RE: Field shows a value on the form although a custom code empties it

    The value is being populated by the initValue method that calls the initFromPurchReqTable method.

    What I want to do is clear the field whenever someone creates a new line in a Purchase requisition. I only want to clear this field when the line is created from PurchReqTable that's why I put my code in this place.

    Unfortunately, I tried refreshing the datasource but to no avail. As you pointed out, it only works for saved records and the newly created line is not saved at this point.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Field shows a value on the form although a custom code empties it

    To me it seems that you should use Chain of Command on the initVaule method of the PurchReqLine data source on PurchReqTable form. After calling next(), set Requisitioner field to 0.

    AND call purchReqLine.modifiedField(fieldNum(PurchReqLine, Requisitioner)), just ilke the standard method does.

    Looking at the code, I still think that the field is populated by stadard code AFTER your code (check lines 7-8), and that explains your issue.

            public void initValue()
            {
                if (purchReqTable)
                {
                    if (currentRequisitioner)
                    {
                        purchReqLine.initFromPurchReqTable(purchReqTable);
                        purchReqLine.Requisitioner          = currentRequisitioner;
                        purchReqLine.BuyingLegalEntity      = currentBuyingLegalEntity;
                        purchReqLine.ReceivingOperatingUnit = currentReceivingOperatingUnit;
                    }
                    else
                    {
                        purchReqLine.Requisitioner          = purchReqTable.Originator;
                        this.initInternalOrganizationValues();
                        purchReqLine.initFromPurchReqTable(purchReqTable);
                    }
                }
    
                purchReqLine.LineType = PurchReqLineType::Category;
                purchReqLine.modifiedField(fieldNum(PurchReqLine, Requisitioner));
    
                element.updateDefaultDimension();
    
                super();
            }

  • Alexandre Sarazin Profile Picture
    48 on at
    RE: Field shows a value on the form although a custom code empties it

    Lines 7-8 are actually there to populate the field for new lines after the first one so that the Requisitoner from the first line is copied to the other lines. I still want this to function.

    For the first line of the Purchase Requisition, the variable currentRequisitioner is empty and the lines 14-16 are run. So in my case, my code will actually empty the field as intended.

    I also tried your suggestion by emptying the field in the initValue chain of command method and calling the modifiedField. But I get the same results. The field in the record is empty, but the FormControl is still showing a value. Here is what I get in Dynamics :

    pastedimage1625141743891v1.pngpastedimage1625141837059v2.png

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Field shows a value on the form although a custom code empties it

    I still think that you'll find the answer by studying how this form is implemented.

    Next thing that I noticed is the modified() method of ItemId. There the system modifeid the Requisitor, and does some tricks.

    For example this section:

                  		requester               = purchReqLine.Requisitioner;
                        buyingLE                = purchReqLine.BuyingLegalEntity;
                        receivingOperatingUnit  = purchReqLine.ReceivingOperatingUnit;
    
                        purchReqTableForm.resetPurchReqLine(purchReqLine);
    
                        purchReqLine.Requisitioner          = requester;
                        purchReqLine.BuyingLegalEntity      = buyingLE;
                        purchReqLine.ReceivingOperatingUnit = receivingOperatingUnit;
    
                        purchReqLine_ds.resetLine();

    If it still doesn't work, just try to find all places in this form that handle Requisitor - some of them must contain the solution.

  • Alexandre Sarazin Profile Picture
    48 on at
    RE: Field shows a value on the form although a custom code empties it

    The modified() method is not called. I tried to call the resetLine() method but it's also not working.

    I already searched the code of the form but I didn't find any logic that would cause this issue.

    My guess is that the control is a reference group and it isn't properly refreshed with the last value in the record. Although I don't really see why that would happen...

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,933

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 793 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 537 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans