How can I tell if a journal line entity is a custo...
# suitescript
m
How can I tell if a journal line entity is a customer or a vendor via suitescript?
entitytype
seems to only return
Entity
c
How are you getting the value for
entitytype
?
m
I was just doing like getSublistValue('line', 'entitytype', lineNumber)
I wonder if I can do a getsublistvalue join... edit- doesn't look like it
c
*untested
m
yeah with 2 steps that makes sense. Was hoping to do it in 1 though, this map/reduce script is already quite large
c
Is this during getInputData or a map / reduce stage?
m
map/reduce
c
It's not much of an additional load on governance if it's just happening 1x per map execution. An alternative is to structure your getInputData so that the entity type is joined into your context value.
Hard to say without more details about how you're implementing this and what your goals are
m
getinput is only getting journal entries (with specific expense accounts), the reduce is looping through 1000s of lines on each journal entry
👍 1
but no worries, thank you for the advice
I may end up going the 2 step version, just was wondering if there was a more straightforward way
c
Depending on what you need to do with the data from the lines of the journal, could you run a query in your reduce to fetch the data you need? Or are you editing the Journal lines 1 x 1 depending on the line values?
m
I am editing each individual line that has a specific expense account yes. In this specific instance the journals are thousands of lines long and every Name field is a Customer field, even though for all of these thousands of fields it should be a Vendor instead. I'm getting the vendor by a custom PO # field on the line, doing a search to go see if that PO # exists, and if not using a fallback Misc Vendor. Setting that on the Name field and a custom Vendor (Expense) field
and the script is run regularly, to update old journal lines with new vendor values if the PO has been added to netsuite since the last time it was run. So on first run it'll be doing a huge number of individual line updates (based on the PO #), and then on subsequent passes it'll be doing some updates, but a lot less, but it's hard to tell in the script if I'd need to update the line ahead prior to 'processing' it again
Sorry for the extended description
c
Can you filter to only lines that have customers in your getInputData function?
And use that data to inform your updates in a later stage
w
Why not get all unique ids from the lines (no governance once the rec is loaded) and then run a suiteql to get an id-to-type hash-map that you can reference in the script?
Feels like this also could be fixed in getInputData with a query that gives you everything you need.
m
So the suggestion is to get journal lines in the getinputdata method? This would be 10s of thousands of lines. And pass those to the map/reduce functions?
And in the map/reduce I'd be loading the lines somehow? Not the journals?
w
I would still load the journal. But the query might be possible to construct so that you know which lines to update and with what.
🌟 1
m
With my current script I am getting
Script Execution Usage Limit Exceeded
hmm
c
@mrob In which stage?
m
reduce
I had to back up though, some of the vendors I'm trying to set are inactive. So now accounting wants a list of all inactive vendors that appear on any of these 10s of thousands of journal lines
Trying to temporarily make the vendors active is failing b/c of some workflow somewhere though
I had hoped submitValue would skip workflows
One step forward, two steps back
c
If you can have all of them reactivated for a short time, you could use CSV import to change the inactive field while skipping scripts & workflows, then repeat the process to deactivate the list after.
m
Yeah good idea, that would require me to be able to find all the vendors ahead of time though
Going back to the initial problem statement, these journal entry lines don't even have the vendor associated properly yet. So I need to get all the PO ID fields from the journal entry lines (with the right expense account #), see if there is a PO in netsuite that matches the tranid, then pull the vendor and see if it's inactive
the other issue is that this is not necessarily a one-time thing I'd need to do
c
You can find inactive vendors associated with the PO tran IDs on the Journals using a query
m
It may have to happen every month
c
Do you have the option of editing the execution context filtering of the workflow to bypass edits made using map/reduce?
m
I think this is a separate script though, I can't see how to do it in the map/reduce. maybe in the getinputdata stage...?
Yes an no. The workflows were made by someone else and they are a mess
and i'm tired of cleaning up after that person
But yes I don't think he's responsible enough to actually make the changes himself so I have to do it. I'll work on doing that for awhile
c
Assuming that your company doesn't require the logic associated with that workflow for other use cases, it's a quick process to update the workflow's context so it doesn't run for Map/Reduce scripts
m
Yeah, there's just 12+ of them that run every time a vendor record is so much as viewed
and I hate monkeying with his workflows because they're all so finicky. They regularly break our netsuite instance
Looks like 28 of them...
c
oof I hear you
m
I'm so stuck on trying to get these inactive vendors in a semi-performant manner. I'm trying to build a suiteql query (with a lot of input from chatgpt) and can't get the journal lines to join to the journal entry. Any idea? Something as basic as
Copy code
var suiteQL = `
    SELECT T.ID, T.TRANID, TL.ACCOUNT
    FROM TRANSACTION T
    INNER JOIN TRANSACTIONLINE TL ON T.ID = TL.TRANSACTION   
    WHERE T.TYPE = 'Journal Entry'
`;
var queryResults = query.runSuiteQL(suiteQL);
is returning no results
type is Journal... stupid chatgpt