Search code examples
axaptax++dynamics-365-operations

D365FO: Update non-editable table field with data entity


I have a following problem: I have a tableA (standard FO table) that has a fieldA (string) with the Allow Edit property set to to No. Now the user would like to have several fieldA values changed with an added suffix, for example: FOO -> FOO_bar.

Can I do some sort of an CSV import that has old and new values or what would be the best way for start solving this?


Solution

  • You can by code update the field irrespective of the fields AllowEdit property. This only affects its use in forms.

    You can import a file as described here.

    public  void UploadFileData()
    {    
        var fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
        var file = AsciiStreamIo::constructForRead(fileUpload.openResult());
        if (!file || file.status())
        {
            throw error("@SYS52680");
        }
        file.inFieldDelimiter(',');
        file.inRecordDelimiter('\r\n');
        for (var record = file.read(); !file.status(); record = file.read()) 
        {
            record = file.read();
            if (record)
            {
                info(strFmt("%1 - %2",conPeek(record,1),conPeek(record,2)));
            }
        }
    }