0

I encountered a problem in the development, requesting a new purchase request line of a purchase with a legal person with a default value of empty

I tried a variety of methods, the default value can not be overriden.

The following is my code.

[ExtensionOf(formDataSourceStr(PurchReqTable, PurchReqLine))]
final class IWS_PurchReqTable_FDS_Extension
{
   
    public void initValue()
    {
        next initValue();
        //ttsbegin;
        PurchReqLine purchReqLine = this.cursor();
        purchReqLine.BuyingLegalEntity = 0;
        purchReqLine.modifiedField(fieldNum(PurchReqLine,BuyingLegalEntity));        
        this.rereadReferenceDataSources(); //Refresh value
        this.reread();
        this.research(1);
        

        FormReferenceGroupControl BuyingLegalEntity = this.formRun().design().controlName(formControlStr(PurchReqTable, PurchReqLine_BuyingLegalEntity));
        FormStringControl BuyingLegalEntity_DataArea = this.formRun().design().controlName(formControlStr(PurchReqTable, PurchReqLine_BuyingLegalEntity_DataArea));
        BuyingLegalEntity.value(0);


        BuyingLegalEntity.resolveChanges();
        BuyingLegalEntity.referenceDataSource().research(1);
        BuyingLegalEntity.modified();
        //BuyingLegalEntity_DataArea.text('');
        //BuyingLegalEntity_DataArea.modified();

        purchReqLine.BuyingLegalEntity = 0;
        purchReqLine.modifiedField(fieldNum(PurchReqLine,BuyingLegalEntity));
        //purchReqLine.update();
        //purchReqLine.insert();
        //this.rereadReferenceDataSources();
        //this.refresh();
        //this.reread();
        //this.resetLine();
        //ttscommit;
    }
    //End

}

Screen capture

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50

1 Answers1

0

It is not totally clear to me what you are trying to do.

Most values are "born" zero or blank and if that is not the case for this field, something else is setting the field, maybe after your code in initValue is called. The cross reference may be of good value here to find the code that references the field.

First of, you should definitely not reference the controls, also calling modifiedField and research from here is a total no-go.

For a start try this:

public void initValue()
{
    next initValue();
    purchReqLine.BuyingLegalEntity = 0;
}

It simply sets the field to zero. Do not worry about the field control, it will be rendered from the buffer value after the call to initValue.

If that does not solve your problem, something else is setting the field. You can set a breakpoint here, then follow to code until the field is set. Also add the value to the watch list, maybe do conditional debugging.

If another extension for this datasource exist it may override your behaviour as the execution order of extensions is arbitrary.

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
  • I tried this method, and then I debug traced it many times, and tried many methods, but one strange thing is that I will have the default value when I create the first row, and the default value will be empty when I create the second row. – ZHI JIANG Feb 16 '22 at 07:56
  • Did check the references to the field? – Jan B. Kjeldsen Feb 16 '22 at 08:55