Hi. Stumbled upon this article. <https://netsuite....
# suitescript
j
Hi. Stumbled upon this article. https://netsuite.smash-ict.com/learn-how-to-implement-prominent-custom-state-labels-on-netsuite-records/ Can anyone help to rewrite is so that if custbody_status = 1 then show green ”Yes” and if custbody_status = 2 then show red ”No” ?
b
that is an application of an if...else and Record.getValue
e
Should be as simple as: line 19
let stateTxt = 'Yes';
line 20
let errState = scriptContext.newRecord.getValue({ fieldId: 'custbody_status' }) == 2;
line 23
let bgColor = NsLabelColor.GREEN;
Around line 25, add
stateTxt = 'No';
The rest should stay the same. This isn’t exactly what you stipulated; it assumes Yes/GREEN for every status other than 2. You may add if statements for status == 1…
👍🏼 1
b
you will also want to know the general weakness of the code from the example, fundamentally it relies on netsuite naming its css classes a certain way, as mentioned in the article, its dom manipulation, You can still do it, but expect to pay extra maintenance costs to make sure it continues to work the implementation given here also relies on NetSuite exposing the jQuery global, and that inline html fields support script elements. both of these are things that could be fixed by actually implementing a proper client script
e
how so, @battk without DOM manipulation? Would require you to paint a message (or in beforeLoad User Event script you can do the same), but you don’t have access via SuiteScript to manipulate this specific “status” area. Correct?
j
Thank you guys! I have deployed the script, no error message in the logs, but no new ”status” message is shown. Does it work for you?
b
i wouldnt expect any errors thrown by that script to go to script logs
the try catch only handles code in the user event script, while the most likely place to error will be client side
which means the error will be thrown to the developer console
j
I've done something similar, but probably a lighter touch approach to adding in additional info to the labels. 1. Add inline HTML field 2. Use workflow in before-load state to set the HTML field value to HTML with script tags 3. eg. adds ' - Expense Approver' to the 'pending approval' state so it reads Pending Approval - Expense Approver <script> document.getElementsByClassName("uir-record-status")[0].innerHTML=document.getElementsByClassName("uir-record-status")[0].innerHTML + " - Expense Approver" </script>
👍 1
e
@Jesper M you should post your code here