I'm trying to debug an old scheduled script writte...
# suitescript
b
I'm trying to debug an old scheduled script written in SuiteScript 1.0. It fails at
nlapiSubmitRecord()
sometimes with RCRD_HAS_BEEN_CHANGED. Just before that, there's a loop that sets values on the record's lines. In the loop, there's also a check to get the governance usage and yield if it's less than 200 remaining. My theory is it's reloading the record (
nlapiLoadRecord()
) after it yields. Can anyone confirm my theory? Is a SuiteScript 1.0 scheduled script smart enough to not reload the record when yielding?
n
Yeah when a Suitescript 1 record yields it loads the record again from scratch. So effectively throwing out all the record progress. SS2 passes the loaded script object back into the script context when it resumes. But 1 does not
🙌 1
b
Sweet. Thank you
🫡 1
b
Would either of you mind explaining what 'yield' means here? I'm running into that error at times with SS 1.0 scripts that I've been charged with to maintain...
b
Each SuiteScript function consumes a certain number of governance. Each type of script has a limit to how much governance can be consumed. SuiteScript 1.0 scripts require the developer to manage the governance usage. If the usage exceeds the limit, the script with fail at that point. There's a method for getting the current remaining governance usage, which you can use to tell if your script is nearing the limit.
Copy code
nlapiGetContext().getRemainingUsage();
Before the script reaches the limit, you can yield it. This causes the current memory usage to get saved into storage and your script gets restarted with the memory reloaded from storage.
Copy code
nlapiYieldScript();
🤯 1
n
SuiteScript 2 does this automatically for you in things like map/reduce scripts. Since MR scripts execute in a queue, if one takes a long time to complete, it will yield after a set amount of time from the deployment record, and re-queue itself to allow other scripts to run. When it yields in SS 2 the progress of the script is cached. So that when the script begins to run again it picks up from where it left off.
👀 1
b
@burkybang 🤯 I know about governance but I the yield command is new to me! Thanks. Also you, @Nathan L.
b
No prob. Manually having to yield is only applicable to scheduled scripts.
n
"_SS2 passes the loaded script object back into the script context when it resumes. But 1 does not_" Further to this, I don't believe you can manually yield a scheduled script in SS2 as you could with S1.0. Happy to be proven wrong though. Help says "If you have a scheduled script with potentially long execution times, you should consider using a map/reduce script instead. SuiteScript 2.x does not have a method to allow you to set recovery points or provide a yield to avoid exceeding the allowed governance for a scheduled script. A map/reduce script has built-in yielding and can be submitted for processing in the same ways as a scheduled script." Just leaving this here before anyone fancies re-authoring a SS1.0 SS script to SS2.
💯 1