0

I am using strong soap in node to extract a saved search in Netsuite. I have had some success but now I have the information in node I need to extract the values.

If I use util.inspect on the results of the search query then I get a long detailed breakdown of all the information in the search.

If I just use console.log to print the results then I get the below.

The information I need is inside the entityId and customFieldList objects.

How do I go about accessing these objects?

[
  {
    '$attributes': { '$xsiType': [Object] },
    basic: { entityId: [Object], customFieldList: [Object] }
  },
  {
    '$attributes': { '$xsiType': [Object] },
    basic: { entityId: [Object], customFieldList: [Object] }
  },
  {
    '$attributes': { '$xsiType': [Object] },
    basic: { entityId: [Object], customFieldList: [Object] }
  },
  {
    '$attributes': { '$xsiType': [Object] },
    basic: { entityId: [Object], customFieldList: [Object] }
  },
  {
    '$attributes': { '$xsiType': [Object] },
    basic: { entityId: [Object], customFieldList: [Object] }
  },
  {
    '$attributes': { '$xsiType': [Object] },
    basic: { entityId: [Object], customFieldList: [Object] }
  }
]

Thank you for the effort to help so far.

when I use util.inspect then each of the above sections breaks down like the below. I have asterisks the sensitive info, but essentially the values I need are the searchValue for entityId and customField.

{
  status: { '$attributes': { isSuccess: 'true' } },
  totalRecords: 6,
  pageSize: 1000,
  totalPages: 1,
  pageIndex: 1,
  searchId: '****************************************************************',
  searchRowList: {
    searchRow: [
      {
        '$attributes': {
          '$xsiType': {
            type: 'EmployeeSearchRow',
            xmlns: 'urn:employees_2022_2.lists.webservices.netsuite.com'
          }
        },
        basic: {
          entityId: { searchValue: '*****' },
          customFieldList: {
            customField: [
              {
                '$attributes': {
                  internalId: '****',
                  scriptId: 'custentity_revenuetoday_stored',
                  '$xsiType': {
                    type: 'SearchColumnDoubleCustomField',
                    xmlns: 'urn:core_2022_2.platform.webservices.netsuite.com'
                  }
                },
                searchValue: '*****'
              },
              {
                '$attributes': {
                  internalId: '****',
                  scriptId: 'custentity_wallboard_yn',
                  '$xsiType': {
                    type: 'SearchColumnBooleanCustomField',
                    xmlns: 'urn:core_2022_2.platform.webservices.netsuite.com'
                  }
                },
                searchValue: 'true'
              }
            ]
          }
        }
      },

Sebastian's answer below is what you need if you get the same problem. Code I used of his was:

          const searchRows = result.searchResult.searchRowList.searchRow;
          searchRows.forEach((row) => {
             const searchValue = row.basic.entityId.searchValue;
             const customField = row.basic.customFieldList.customField.searchValue;
             console.log(searchValue);
             console.log(customField);
          });
  • 1
    It is an array of objects, so, like this? `objArray[index].basic.entityId` and `objArray[index].basic.customFieldList` – GrafiCode Aug 23 '23 at 12:06
  • 1
    Does this answer your question? [How can I access and process nested objects, arrays, or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – Matt Morgan Aug 23 '23 at 12:52
  • Hi Matt, thank you, believe it or not I spent much of the morning reading that incredibly detailed reply and have tried the techniques from the 'accessing nested data section' and the 'what to do if I don't know the structure beforehand part' and no joy sadly. Matt, Grafi, I am going to post the breakdown of the objects above as per util.inspect which will probably help. Appreciate both of your time, thank you for trying to help. Just give me a couple of minutes to sanitise the data. – TheIronKing Aug 23 '23 at 13:00

1 Answers1

1

If that's your results object, then you can access a single value like this:

const query = {
  status: { '$attributes': { isSuccess: 'true' } },
  totalRecords: 6,
  pageSize: 1000,
  totalPages: 1,
  pageIndex: 1,
  searchId: '****************************************************************',
  searchRowList: {
    searchRow: [
      {
        '$attributes': {
          '$xsiType': {
            type: 'EmployeeSearchRow',
            xmlns: 'urn:employees_2022_2.lists.webservices.netsuite.com'
          }
        },
        basic: {
          entityId: { searchValue: '*****' },
          customFieldList: {
            customField: [
              {
                '$attributes': {
                  internalId: '****',
                  scriptId: 'custentity_revenuetoday_stored',
                  '$xsiType': {
                    type: 'SearchColumnDoubleCustomField',
                    xmlns: 'urn:core_2022_2.platform.webservices.netsuite.com'
                  }
                },
                searchValue: '*****'
              },
              {
                '$attributes': {
                  internalId: '****',
                  scriptId: 'custentity_wallboard_yn',
                  '$xsiType': {
                    type: 'SearchColumnBooleanCustomField',
                    xmlns: 'urn:core_2022_2.platform.webservices.netsuite.com'
                  }
                },
                searchValue: 'true'
              }
            ]
          }
        }
      },
      // ... more results
    ]
  }
};

const searchValue = query.searchRowList.searchRow[0].basic.entityId.searchValue;
const customField = query.searchRowList.searchRow[0].basic.customFieldList.customField;

console.log(searchValue);
console.log(customField);

Notice that I hardcoded the 0 index to access the first result's values. If you want to access all of the values you can iterate over them:

const query = {
  status: { '$attributes': { isSuccess: 'true' } },
  totalRecords: 6,
  pageSize: 1000,
  totalPages: 1,
  pageIndex: 1,
  searchId: '****************************************************************',
  searchRowList: {
    searchRow: [
      {
        '$attributes': {
          '$xsiType': {
            type: 'EmployeeSearchRow',
            xmlns: 'urn:employees_2022_2.lists.webservices.netsuite.com'
          }
        },
        basic: {
          entityId: { searchValue: '*****' },
          customFieldList: {
            customField: [
              {
                '$attributes': {
                  internalId: '****',
                  scriptId: 'custentity_revenuetoday_stored',
                  '$xsiType': {
                    type: 'SearchColumnDoubleCustomField',
                    xmlns: 'urn:core_2022_2.platform.webservices.netsuite.com'
                  }
                },
                searchValue: '*****'
              },
              {
                '$attributes': {
                  internalId: '****',
                  scriptId: 'custentity_wallboard_yn',
                  '$xsiType': {
                    type: 'SearchColumnBooleanCustomField',
                    xmlns: 'urn:core_2022_2.platform.webservices.netsuite.com'
                  }
                },
                searchValue: 'true'
              }
            ]
          }
        }
      },
      // ... more results
    ]
  }
};

const searchRows = query.searchRowList.searchRow;
searchRows.forEach((row) => {
  const searchValue = row.basic.entityId.searchValue;
  const customField = row.basic.customFieldList.customField;

  console.log(searchValue);
  console.log(customField);
});
Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
  • Sebastian, thank you. You are a genius. I didn't use the exact code, as I didn't need the query part, but in essence, this was exactly it. Thank you. – TheIronKing Aug 23 '23 at 14:17