This topic contains 5 replies, has 0 voices, and was last updated by ironside 7 years, 7 months ago.
-
AuthorPosts
-
April 10, 2017 at 10:32 pm #21646
sklettI'm very rusty with my client script, but I do recall running into this same problem years ago, hopefully someone here has a solution.
Requirement: Using client SuiteScript restrict edits to the quantity column on sales orders and display an alert to the user. No Workflow, no custom forms, no UE script to make columns disabled – must be client side SS. This isn't my real use case, but it accurately represents my technical needs.
Problem: NetSuite fires the validateField event whenever a field loses focus. The validateField handler is the natural choice to reject a user edit (by returning false). If my quantity field receives focus, then the user clicks out of the browser window the validate event is raised, my client code runs and shows the alert. When the user clicks the alert OK button, it triggers the validateField event again and so begins the endless loop.
Before I hack together some state management or other solution to avoid multiple alert popups I wanted to ask if anyone here has a better pattern or strategy for rejecting user edits and avoiding re-triggering the event when focus is lost?
Here's what I have so you can see things are basically correct.
PHP Code:
/**
* Event raised whenever a user edits a field. This handler will utilize the controller object to determine if
* the current field can be edited or not.
* @param {string} fieldId The id of the field to validate
* @returns {boolean} Whether or not the current field is valid
* @private
*/
var _onValidateField = function(type, fieldId) {// We only care about item field changes…
if(type != 'item') {
return true;
}try {
if (!_controller.canEdit(fieldId)) {
return false;
}
} catch(e) {
return false;
}return true;
};
This is a cached copy. Click here to see the original post. -
April 10, 2017 at 11:03 pm #21647
Vesku1980Do you have Return True in your script when validating the field?
This is one of my scripts in use :
function ValidateField(type, name)
{
if (name === 'entitystatus')
{
var entitystatus = nlapiGetFieldValue('entitystatus');
var itemCount = nlapiGetLineItemCount('item');
var customRecordCount = nlapiGetLineItemCount('recmachcustrecord_mpc_cajo_ oppotunity')
console.log('entitystatus_'+entitystatus);
console.log('itemCount_'+itemCount);
console.log('customRecordCount'+customRecordCount) ;
if (entitystatus == '7' && ( itemCount == '0' || customRecordCount == '0'))
{
alert('You can't set Lead Status to qualified with this data! Please add an item and segment information.');
return false;
}
}
// Always return true at this level, to continue validating other fields
return true;
}
Hope that this will help you!
Vesku
-
April 10, 2017 at 11:39 pm #21648
sklettThanks for the suggestion, but yes, I'm returning true where appropriate. I've updated my original post with a simplified code sample.
-
April 11, 2017 at 3:56 am #21649
NelliottThis doesn't address your issue directly but maybe employing showAlertBox would be better than an alert and potentially break your loop.
showAlertBox("myelement_id","You did bad things","stop entering rubbish",0,"","","","")
Parameters below
a = id of ui element, (whatever you want).
b = Title
c = Message
d = severity –
0 – Confirmation (green)
1 – Blue
2 – Yellow
3 – Red
set the last three to "".
If you use the same id in the first parameter it will overwrite the message, if you supply a different id you will see new messages uniquely in the page.
You can try this straight form the console btw
Good Luck,
Neil
-
April 11, 2017 at 9:32 am #21650
erictgrubaughIs your primary goal actually to reject an edit, or to prevent it altogether in the first place? Even without a UE script, could you leverage `lineInit` to disable the `quantity` (or whichever) column you don't want modified?
-
April 17, 2017 at 6:33 pm #21651
ironsideHowdy sklett. You can try
Code:
_.debounce()
orCode:
_.throttle()
as simple workarounds. Since you're surely using NFT by now lodash is already there for you -
AuthorPosts
You must be logged in to reply to this topic.