Is there a way to trigger a percent field to show ...
# suitescript
j
Is there a way to trigger a percent field to show as a percent when doing a
setValue
on it, while still having ignoreFieldChange set to false? I want it to show properly but not trigger FieldChange events.
b
use setText
j
Unfortunately that doesn’t seem to work. My code is
tx.setCurrentSublistText({sublistId: sublist_id, fieldId: 'custrecord_subscr_participation', text: '67.0%', ignoreFieldChange: true});
and I get this:
Whereas I am hoping for this:
(which is what I get if I allow field change and use setValue to set it to 67)
b
sounds strange, how is your sublist and field setup
s
@jen what you've showed is the expected behaviour, the workaround I can think of right now is you allow ignorefieldchange to be false, but in the field changed function , do an if statement and a return to "escape"
j
@Sciuridae54696d “expected behaviour”….do you work for NetSuite Support 😉 ? But the thing is, under certain circumstances, I DO need the fieldchange to run, but I need to be able to set the value sometimes WITHOUT it running.
@battk it’s just a custom record that has parent set to Opportunity. Field is just one of the custom fields on my custom record.
b
you need to be more specific, to the level where I can recreate the field and sublist myself
s
@jen my testing before is if you leave ignore field change to true at least for the percentage field, it doesn't seem to set the percentage field as percentage, and will leave it as a number/text for fields that exhibit hybrid behavior, as in both dollar amount and percentage, it would become invoncenient. I'm almost tempted to tell you I feel the workaround is actually do the calculation in the back end, and leave this field out of other calculations. Or... leave what you want to do latter in post sourcing and have this in ignorefieldchange as false Neither is nice, but I'm pretty sure within the puzzle, both will functionally work
j
@battk I have a custom record called “Subscriber” which has a few fields, one of which is
custrecord_subscr_participation
. It also has a field of type Transaction (
custrecord_subscr_transaction
) which has ‘Record is parent’ set, so that the sublist of Subscriber records appears on a Transaction. It also has some other fields. There are a few things that cause Subscribers to be added to the sublist: • on PageInit (based on some other fields in the Transaction) a set of Subscribers are added as new lines in the Subscriber sublist. This is done with
selectNewLine()
, a few `tx.setCurrentSublistValue()`s, and a
commitLine()
• when a user clicks a particular button (which is actually just some HTML I’ve put in an inlineHTML field on the transaction that looks like a NS button, and calls a client-side function) a set of Subscribers are added as new lines in the Subscriber sublist (similar way to in PageInit) • a user can manually insert a new Subscriber to the sublist in the UI There is certain logic that needs to run when the percent field is changed in that sublist, which is triggered by the
FieldChange
in the Custom Form script. However, I need to control when this does and doesn’t happen (for example, I don’t want that to run when the Subscribers are added as part of the PageInit). As a result, I want to be able to use ignoreFieldChange: true while still having the percent field appear as a percent (with the % symbol) rather than just a number. However, the only way to make it show as a formatted percentage seems to be to set the value with ignoreFieldChange set to false.
b
took a look, the percentage field relies on the onchange event to copy that percentage value around
id go without making your fieldChanged entry point smart enough to ignore the changes you make during pageInit
alternatively you can do something weird like triggering a blur event on the field, which should update the field's value
less weird is just straight up doing the dom manipulation
j
Thanks for confirming that I’m not going crazy 😉 I will likely go with the DOM manipulation method.