I am hoping somewhere here has some experience with this. I'm on the last leg of my script and I cannot figure out, for the life of me, why this is not working properly.
I basically have an array that contains the 'itemid' for multiple items. To keep it simple, in this example, The array is as follows:
searchResults[0].getValue('itemid') = '12345'
searchResults[1].getValue('itemid') = '12345'
searchResults[2].getValue('itemid') = '12345'
I'd like to get only unique values for the itemid field, based off of my search results. I've tried the following:
When I don't use the group function, it seems to be passing the values properly
This causes my seachresults[0].getValue('itemid') = '12345'
This causes my seachresults[1].getValue('itemid') = '12345'
This causes my seachresults[2].getValue('itemid') = '12345'
Use the group function in the columns:
columns[0] = new nlobjSearchColumn("itemid",null,"group");This causes my searchresults.length = 1, which is correctThis causes my seachresults[0].getValue('itemid') to be blank (or null)Pass the values to a traditional Javascript Array and then gather unique values: filters[0] = new nlobjSearchFilter("custrecord_count_id",null,"is",countID); columns[0] = new nlobjSearchColumn("itemid"); columns[0].setSort(); var tempUnique = nlapiSearchRecord('customrecord_count_details', null,filters, columns); var valueToPush = { }; var allItems = new Array (); for(var i = 0; i < tempUnique.length; i++) { valueToPush["item"] = tempUnique[i].getValue('itemid'); allItems.push(valueToPush); } // THE ABOVE SECTION BUILDS THE ARRAY (allItems) CORRECTLY // NOW I WILL TAKE UNIQUE VALUES INTO A NEW ARRAY var uniqueItems = []; for(var i = 0; i < allItems.length; i++) { if (uniqueItems.indexOf(allItems[i]) == -1) uniqueItems.push(allItems[i]); }This also causes the values to go to blank (or null)If anyone can guide me on how to pull these unique values properly, I would appreciate it!