Corey Schwoebel
12/07/2023, 9:27 PMCorey Schwoebel
12/07/2023, 9:28 PMClay Roper
12/07/2023, 9:46 PMline
field? From what I remember on a recent project, it's not populated on a new line until it's committed.Corey Schwoebel
12/07/2023, 9:51 PMClay Roper
12/07/2023, 9:53 PMClay Roper
12/07/2023, 9:54 PMCorey Schwoebel
12/07/2023, 9:54 PMClay Roper
12/07/2023, 10:01 PMCorey Schwoebel
12/07/2023, 10:02 PMClay Roper
12/07/2023, 10:04 PMClay Roper
12/07/2023, 10:04 PMLucas
12/08/2023, 7:09 AMvalidateLine
or validateInsert
function to set the marker field whenever a line is added or edited.
◦ Example:
function validateLine(scriptContext) {
var sublistName = scriptContext.sublistId;
if (sublistName === 'your_sublist_id') {
// Set the marker field value
var currentLine = scriptContext.currentRecord.getCurrentSublistIndex({ sublistId: sublistName });
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: sublistName,
fieldId: 'custpage_marker_field',
value: 'committed',
ignoreFieldChange: true
});
}
return true;
}
Check the Marker on Field Change:
• In the fieldChanged
function, check the value of the marker field to determine if the current line is new or being edited.
• Example:
function fieldChanged(scriptContext) {
var sublistName = scriptContext.sublistId;
var fieldId = scriptContext.fieldId;
if (sublistName === 'your_sublist_id' && fieldId === 'a_field_in_sublist') {
var markerValue = scriptContext.currentRecord.getCurrentSublistValue({
sublistId: sublistName,
fieldId: 'custpage_marker_field'
});
if (markerValue === 'committed') {
// Line has been committed
} else {
// New line or uncommitted line
}
}
}
Other Approaches
• Record ID Check: If each line in the sublist is associated with a unique ID (like an internal ID), you can check if this ID exists or is set. New lines usually won't have an ID until they are committed.
• Line Index Tracking: Maintain the index of the last committed line. Any line index greater than this indicates a new line.
Considerations
• The specific implementation details can vary based on the NetSuite record type and the structure of your sublist.
• Ensure that your client script does not adversely impact the user experience with unnecessary complexity or performance overhead.
• Always thoroughly test your client scripts in a sandbox environment before deploying them to production.
These methods provide a basis for differentiating between new and existing lines in a sublist using client scripting in NetSuite.Lucas
12/08/2023, 7:10 AMcurrentRecord.getCurrentSublistValue({ sublistId: 'your_sublist_id', fieldId: 'internalid' })
.
• You can compare this ID with the initial ID you assigned to the line when it was first added. If they are the same, the line hasn't been committed yet.
• This approach works well for newly added lines but may not be reliable for existing lines edited within the sublist.
2. Checking the isEditMode
property:
• Client scripts also provide a currentRecord.isEditMode()
property that indicates whether the current record is in edit mode.
• While this doesn't directly tell you about the sublist line, you can combine it with the previous approach to improve accuracy.
• If isEditMode
is true and the line ID is different from the initial ID, it implies an existing line being edited.
3. Using custom fields:
• You can create a custom field on the sublist record to track the commit status of each line.
• When adding a new line, set this field to "Uncommitted" and update it to "Committed" after the line is saved.
• In your client script, check the value of this field to determine the line's commit status.
4. Using validateLine
or sublistChanged
scripts:
• SuiteScript provides validateLine
and sublistChanged
entry points for client scripts.
• The validateLine
script is triggered before a line is added to the sublist, while sublistChanged
is triggered after any changes to the sublist.
• You can use these scripts to set a flag or custom field indicating that the line is new and hasn't been committed yet.Lucas
12/08/2023, 7:11 AMNElliott
12/08/2023, 9:08 AMcurrentRecord.getCurrentSublistValue({ sublistId: 'your_sublist_id', fieldId: 'internalid' })
.
🙄alien4u
12/08/2023, 3:08 PMLucas
12/08/2023, 3:11 PMalien4u
12/08/2023, 3:13 PMlineuniquekey
from existing lines while new lines should not have that value.
Another approach I like, especially with Client Scripts and 2.1 is to read in the pageInit the lines and create a global object which could be used as your index or whatnot to compare.
So on pageInit you build this object with the existing lines.
Then on line changes you check if you already have that line in your object and go from there.Corey Schwoebel
12/08/2023, 3:20 PMalien4u
12/08/2023, 3:21 PMalien4u
12/08/2023, 3:22 PM