This message was deleted.
# suitescript
s
This message was deleted.
b
you arent creating 1 vendor bill with 2 items. you are creating 2 vendor bills with 1 item
👍🏻 1
v
where it is wrong.
i need 1 vendor bill with 2 items
what should i do?
b
identify how many times you are using record.create to create a vendor bill per iteration of your loop
if searchValues had a length of 1, how many times is record.create called, same for a length of 2 or 3
v
i have 2 search values. each search value has 2 line items. so i have to create two vendor bills each has two line items.
how to find the lines of items i can add to the each vendor bill record?
b
you have an array of search values
each one with an item
if each search value had multiple items, your code doesnt make sense
v
yes now i got it what you mean.
could you please tell me then what can i do to add those two items to the single vendor bill record?
i have searchValues (which has 2 vendorbills). i have searchValue(which has 1 vendorbill of 2 line items) now i need to find this searchValue length. could youplease tell me how to find this?
b
your description still doesnt make sense
what string is in searchValues[0]
v
["{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"1000.00\"}","{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"4157.00\"}"]
in searchValues[0]
in this i want to get the length (2). how can i get it. could you please tell me? this is where i am stuck.
b
are you sure thats searchValues[0]
it should be a string, but you shared an array
v
yes i am sure its searchValues[0]
b
context.values should be an array of strings
not an array of arrays of strings
v
Below is searchValue[0], not searchValues{"cusinternalid":{"value":"176869","text":"176869"},"docnumber":"CI22TID00002","vendor":"6228","internalid_subsidiary":"18","represent_subsidiary":"16","item":"175","quantity":"1","fxrate":"333.00"}
Below is searchValue[0], not searchValues{"cusinternalid":{"value":"176869","text":"176869"},"docnumber":"CI22TID00002","vendor":"6228","internalid_subsidiary":"18","represent_subsidiary":"16","item":"175","quantity":"1","fxrate":"333.00"}
b
if searchValue is an array, your statement that there are multiple items makes sense
but your code would not
it would only work if searchValue is an object
v
how to make that as an object ?
with JSON.parse?
b
thats not really the source of confusion here
for example, if searchValues[0] is the string
Copy code
'["{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"1000.00\"}","{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"4157.00\"}"]'
then the first iteration of your loop will look like
Copy code
var searchValue = JSON.parse('["{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"1000.00\"}","{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"4157.00\"}"]');
that line will fail since its not valid JSON
if instead, you mean that searchValues is the array
Copy code
["{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"1000.00\"}","{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"4157.00\"}"]
then you have an array representing one vendor bill, with each element of the array representing one item of that bill
v
then how can it be possible with an array of line items of a single record?
b
the data that you are working with can only represent one vendor bill
with each element of the array representing one line
your code as written will call record.create once for each line
v
shoum
b
which is an attempt at creating one vendor bill per line
v
should i have two for loops?
b
two nested for loops would be appropriate if you had nested arrays
to my knowledge, you just have one array
v
for the second for loop, i need the number of lines of item sublist. how to fetch that from searchValue
b
still dont know what you are trying to do
you shouldnt need a second for loop
v
i have a search of two invoices which has two lines each. with that i am creating two vendorbills each with two lines.
this is what i want to do.
b
sounds reasonable so far
v
now i had the number of invoices (2) to loop thru. in that for loop (every invoice), i need to find the number of lines of item sublist to make it as a second for loop. could you please help me to get that number?
b
this is the point that stops making sense
its likely that you do the search in the getInputData stage, which is going to be the only point where you would be able to get all the search results
you probably have a map stage, which transforms the search result into your searchValue objects
that map stage would only have one search result at a time, so its unlikely to be where you want this logic
that map stage then write values for the reduce stage, where each searchValue is likely keyed by the docnumber
in which case the reduce stage will only process one invoice/vendor bill at a time
so the map and reduce stages dont have access to all the invoices, so it makes no sense to attempt to loop through them
you can probably write logic to loop through the invoices in the getInputData stage, though that doesnt align with what you have shared so far
v
to be honest i am not able to follow you as a newbie to NetSuite. very little i can understand
b
im guessing at your code since you havent shared it in its entirety
you are describing yourself as wanting to do things that dont really make sense for your data
its possible that its sane if you wrote your code in an unusual manner
but nothing you have shared so far says your code is unusual
to my knowledge, context.values is
Copy code
["{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"1000.00\"}","{\"cusinternalid\":{\"value\":\"176368\",\"text\":\"176368\"},\"docnumber\":\"CI22TID00001\",\"vendor\":\"6228\",\"internalid_subsidiary\":\"18\",\"represent_subsidiary\":\"16\",\"item\":\"175\",\"quantity\":\"1\",\"fxrate\":\"4157.00\"}"]
v
its a code from my colleague to finish the last part this one
b
which means that your reduce stage is working with one vendor bill
it makes no sense trying to create multiple vendor bills
v
ok
b
it makes no sense trying to iterate over multiple vendor bills