Hello, I need to export a csv file but append the ...
# suitescript
p
Hello, I need to export a csv file but append the row number that an internal id is in the file. For example if an internal id appears 4 times I need to append a -1 to the first row, a -2 to the next and so on. Is this possible to do and if so how? thank you.
n
Presuming the file is in the filecabinet or being generated in a script as a file object you should be able to manipulate the contents in script.
You may find it easier to work with the contents using the papaparse library btw.
p
I am generating it from a saved search and I am trying to figure out which count for the row that it is for a specific internal id
so if an internal id appears four times I need to make row one with a -1
and then do it for each row
n
I don't understand the logic you're talking about.
p
so if I have 50 rows in my file and the same internal id appears 4 times. I need to go to each of those rows and add the number
I need to keep track in that row which instance it is of that internal id
n
The csv content is likely a multi-dimension array. You can use standard js methods on the array to achieve what you need. Alternatively use papaparse and have it parse the data as JSON if that makes life easier. I imagine from what you're describing you need to iterate through your data once to establish the counts of your various ids and then again to set the value you want on each row. so you may want to have an object something like : { "internalid_a":[1,2,3,5,66], "internalid_b":[11,12,13,15,166], } and then you can see you have 5 rows with the internalid "internalid_a" and the array contains the array index of teh rows that have that value
I have to log now but feel free to DM me tomorrow (I'm on UK time).
p
that is exactly what I am trying to do
thank you
n
^^ if you get stuck, try me tomorrow. 🙂
p
so row 1 would be internal_a_1
thanks
n
You want to append the row number to the internalid essentially?
p
the row instance of the internal id
so if it appears 5 times in the file I need to append the row with its instance
n
I see, that should be easy to do once you have the JSON object formed. So in my example you would put in row 1: internalid_a_1 row 66 would be internalid_a_66 right?
p
if row 66 was the second instance of that internal id it would be _2
not the row number itself
n
Ok so that's fine as you know it's the 4th array element in my example [1,2,3,5,66], (need to add 1 to the index) so on row 66 you'd do "interalid_a_5" simples
really have to go laterz.
p
thanks