I'm having trouble with a map reduce script

50 views Asked by At

I'm creating my first map reduce script. I'm running an item search in the get input stage that outputs:

{ "recordType": "assemblyitem", "id": "XXXXX", "values": { "internalid.memberItem": { "value": "XXX", "text": "XXX" }, "itemid.memberitem": "Member Item is displayed here", "type.memberitem": { "value": "InvtPart", "text": "Inventory Item" }, "memberquantity.memberitem": "", "itemid": "Assembly", "type": { "value": "Assembly", "text": "Assembly/Bill of Materials" }, "quantityonhand": "", "quantitycommitted": "", "quantityonorder": "25", "quantitybackordered": "34", "reorderpoint": "4", "preferredstocklevel": "6", "memberof": "", "memberquantity": "60", "memberbaseunit": "", "quantityonhand.memberItem": "9509", "quantitycommitted.memberItem": "3656", "quantityonorder.memberItem": "", "quantitybackordered.memberItem": "" } }

to the map stage. There I parsed the JSON as "var searchResult" and I'm creating a variable:

var memberItem = searchResult.values.itemid.memberitem;

The issue is I cant figure out is why it is throwing an error "TypeError: Cannot read property "memberItem" from undefined" on every result even though "itemid.memberitem" key and value is in every result set.

Any ideas? Thanks

I've spent hours trying to figure this out but with no success. trial and error is time consuming since I have to execute the script each time I try something else. At this point I'm out of ideas.

1

There are 1 answers

7
d.k On

Short answer, try to use: var memberItem = searchResult.values['itemid.memberitem'];

If you format your JSON:

{
    "recordType": "assemblyitem",
    "id": "XXXXX",
    "values": {
        "internalid.memberItem": {
            "value": "XXX",
            "text": "XXX"
        },
        "itemid.memberitem": "Member Item is displayed here",
        "type.memberitem": {
            "value": "InvtPart",
            "text": "Inventory Item"
        },
        "memberquantity.memberitem": "",
        "itemid": "Assembly",
        "type": {
            "value": "Assembly",
            "text": "Assembly/Bill of Materials"
        },
        "quantityonhand": "",
        "quantitycommitted": "",
        "quantityonorder": "25",
        "quantitybackordered": "34",
        "reorderpoint": "4",
        "preferredstocklevel": "6",
        "memberof": "",
        "memberquantity": "60",
        "memberbaseunit": "",
        "quantityonhand.memberItem": "9509",
        "quantitycommitted.memberItem": "3656",
        "quantityonorder.memberItem": "",
        "quantitybackordered.memberItem": ""
    }
}

you'll see, that you have a property named itemid.memberitem in the values object, which looks like a search join.

On the other hand you do have an itemid property there, which is a string, and it shouldn't be undefined, in your JSON it's 'Assembly', so not sure if this will help.