infor-cloud / m3-h5-sdk

https://infor-cloud.github.io/m3-h5-sdk/
36 stars 20 forks source link

TypedOutput/metadata does not work when calling MI which only returns one value #187

Open mly1971 opened 8 months ago

mly1971 commented 8 months ago

We have an API-transaction which returns one numeric value (REXT) on call (defined as "numeric" in MRS001). Even though typedOutput is set to true the value is always returned as a string. Example:

  const request: IMIRequest = {
     program: 'OIZ156MI',
     transaction: 'ReceivePOLine',
     record: writeOrderLineInput,
     outputFields: ['REXT'],
     includeMetadata: true,
     typedOutput: true
  };

  return this.miService.execute(request).toPromise().catch(this.errorHandler);

Now the strange thing is that the bug only exists if the MI returns exactly 1 value. If it returns 2 or more the error is not present. After intensive debug we found the error in ..\node_modules\@infor-up\m3-odin\dist\mi\runtime.js:

MIServiceCore.prototype.getMetadata = function (content) {
    try {
        var input = content.Metadata;
        if (input && input.Field && input.Field.length > 1) {
                var metadataMap = {};
            var fields = input.Field;
            for (var record in fields) {
                if (fields.hasOwnProperty(record)) {
                    var entry = input.Field[record];
                    var name_2 = entry['@name'];
                    var metaDataInfo = new MIMetadataInfo(name_2, entry['@length'], entry['@type'], entry['@description']);
                    metadataMap[name_2] = metaDataInfo;
                }
            }
            return metadataMap;
        }
    }
    catch (e) {
        // TODO Support some kind of logger injection for logging.
    }
    return null;
};

The problem here is the if-statement in line 4. If only one value is returned "input.Field.length" is undefined and null will always be returned. The metadata IS present in "content" so the code should be modified to handle this

Odin-version: 6.0.0.0

mshgit87 commented 8 months ago

We have an API-transaction which returns one numeric value (REXT) on call (defined as "numeric" in MRS001). Even though typedOutput is set to true the value is always returned as a string. Example:

  const request: IMIRequest = {
     program: 'OIZ156MI',
     transaction: 'ReceivePOLine',
     record: writeOrderLineInput,
     outputFields: ['REXT'],
     includeMetadata: true,
     typedOutput: true
  };

  return this.miService.execute(request).toPromise().catch(this.errorHandler);

Now the strange thing is that the bug only exists if the MI returns exactly 1 value. If it returns 2 or more the error is not present. After intensive debug we found the error in ..\node_modules@infor-up\m3-odin\dist\mi\runtime.js:

MIServiceCore.prototype.getMetadata = function (content) {
    try {
        var input = content.Metadata;
        if (input && input.Field && input.Field.length > 1) {
                var metadataMap = {};
            var fields = input.Field;
            for (var record in fields) {
                if (fields.hasOwnProperty(record)) {
                    var entry = input.Field[record];
                    var name_2 = entry['@name'];
                    var metaDataInfo = new MIMetadataInfo(name_2, entry['@length'], entry['@type'], entry['@description']);
                    metadataMap[name_2] = metaDataInfo;
                }
            }
            return metadataMap;
        }
    }
    catch (e) {
        // TODO Support some kind of logger injection for logging.
    }
    return null;
};

The problem here is the if-statement in line 4. If only one value is returned "input.Field.length" is undefined and null will always be returned. The metadata IS present in "content" so the code should be modified to handle this

Odin-version: 6.0.0.0

Added a PR: https://github.com/infor-cloud/m3-h5-sdk/pull/188

phiko-misc commented 8 months ago

We have an API-transaction which returns one numeric value (REXT) on call (defined as "numeric" in MRS001). Even though typedOutput is set to true the value is always returned as a string. Example:

  const request: IMIRequest = {
     program: 'OIZ156MI',
     transaction: 'ReceivePOLine',
     record: writeOrderLineInput,
     outputFields: ['REXT'],
     includeMetadata: true,
     typedOutput: true
  };

  return this.miService.execute(request).toPromise().catch(this.errorHandler);

Now the strange thing is that the bug only exists if the MI returns exactly 1 value. If it returns 2 or more the error is not present. After intensive debug we found the error in ..\node_modules@infor-up\m3-odin\dist\mi\runtime.js:

MIServiceCore.prototype.getMetadata = function (content) {
    try {
        var input = content.Metadata;
        if (input && input.Field && input.Field.length > 1) {
                var metadataMap = {};
            var fields = input.Field;
            for (var record in fields) {
                if (fields.hasOwnProperty(record)) {
                    var entry = input.Field[record];
                    var name_2 = entry['@name'];
                    var metaDataInfo = new MIMetadataInfo(name_2, entry['@length'], entry['@type'], entry['@description']);
                    metadataMap[name_2] = metaDataInfo;
                }
            }
            return metadataMap;
        }
    }
    catch (e) {
        // TODO Support some kind of logger injection for logging.
    }
    return null;
};

The problem here is the if-statement in line 4. If only one value is returned "input.Field.length" is undefined and null will always be returned. The metadata IS present in "content" so the code should be modified to handle this

Odin-version: 6.0.0.0

Added a PR for the next version so version 7.0.0-next.x #189