Happy Monday! I’m not very script-savvy, but am tr...
# suitescript
k
Happy Monday! I’m not very script-savvy, but am trying to default the required deposit percentage field to 100%. My script sets the field value to 100.0%, but then it reverts back to 0.00 as the record finishes loading. Anyone know how I can get it to stop doing that? Here’s what I’ve got so far:
Copy code
define(['N/record'],
function(record) {

function beforeLoad(scriptContext) {
var newRecord = scriptContext.newRecord ;
newRecord.setValue('requireddepositpercentage', '100');
}

return {
beforeLoad: beforeLoad,
};

});
a
Your better off putting it in a client script.
k
May be you could do before submit
a
That doesn't work if you're trying to set a default.
It will overwrite the value that the user changes.
k
I agree but chances depends and it could be based on what she is trying to achieve! i feel like if she is looking to set as default so user doesn't add or change or those doesn't have value to save with 100% record. so in this case it would work.
a
I am simply trying to answer the question that is posed. Let's wait for her to weigh in.
s
beforeLoad is not for setting values, client script is the better way to approach this. Check the
beforeLoad(scriptContext)
page in the help pages.
Copy code
Data cannot be manipulated for records that are loaded in beforeLoad scripts. If you attempt to update a record loaded in beforeLoad, the logic is ignored.
t
Yeah you cant setValue in beforeLoad
j
except if it’s on create I think
t
Yeah if you're creating a record in beforeLoad you can setValue and submitField, but if youre trying to modify the record the script is executing on it won't work. It's read only
1
k
I am trying to set the field value on create only. If the record already exists, I don’t want to change it. Setting it on submit probably won’t work, as there will be cases where it will be changed.
a
Sounds like your looking for a client script with the pageinit entry point and set the deployment to only apply to on create.
1
👍 1
k
@Alan Fitch IT WORKS! Thank you!
👍 1