Hi guys, i Have been going around over this for th...
# suitescript
l
Hi guys, i Have been going around over this for the last 3 days.... starting to get really frustrated, My goal: update subfield select options based on user input value from the previous selected field in the same line. (I was mainly trying to set: fieldObj.insertSelectOption()) My problems: currentRecord.getSublistField() to get the fieldObj is not available on ClientScript when using Field Change entry point on a new line. And without knowing what the user inputted in the previous field I cant set the select options in server scripts. I tried to find workarounds but I cant think of something with out inserting new values based on user input, I even using support field holding the data but inorder to Disable them based on user input i need to get FieldObj again
Copy code
let setDisable = curRecord.getSublistField({
    sublistId: scriptContext.sublistId,
    fieldId: obj.value,
    line: scriptContext.line
});
setDisable.isDisabled = true
})
I tried using jQuery, when displaying the 3 sublist fields at once department/class/location and when the user is entering the segment field the other 2 will be set to disable but with no success it was too complected for my level the data for the inserted select options is from lists department/class/location in vanilla NetSuite. I open to any suggestion at this point.
c
Not an answer to your question, but this looks awful to use from a user perspective. I'd probably go with the 3 standard segment columns & tell the user the combination they have picked is unacceptable when doing a fieldchanged or validateline
b
your options are to use ss1
or get the field beforehand (in pageInit)
or trick getSublistField into ignoring the line parameter
dom manipulation tends to be too annoying for this task, netsuite redraws the current line multiple times
l
Hi thank you for the quick response, battk can you please provide more detailed explanation on the 2 options you gave?
b
add a line during pageInit, then CurrentRecord.getSublistField to get your field, then remove the line, you can use the same field for multiple lines
Copy code
function getSublistField(options, fieldId, line)
		{
			var sublistId,
				undef = undefined;

			if (fieldId !== undef && line !== undef)
			{
				sublistId = options;
			}
			else if (options !== undef && options !== null)
			{
				sublistId = options.sublistId;
				fieldId = options.fieldId;
				line = options.line;
			}
			utilityFunctions.checkArgs([sublistId, fieldId, line], ['sublistId', 'fieldId', 'line'], getMissingArgumentErrorMessageFillerValue('getSublistField'));
			line = recordUtil.validateAndGetOneBasedIndex(line, "CurrentRecord.getSublistField", nlapiGetLineItemCount(sublistId));

			var fldObj = nlapiGetLineItemField(sublistId, fieldId, line);
			if (fldObj && fldObj.type === fieldTypeConstants.Type.TEXT && getEncodedFieldType(sublistId, fieldId, true) === fieldTypeConstants.Type.CHECKBOX)
				fldObj.type = fieldTypeConstants.Type.CHECKBOX;
			fldObj = fixMissingProperties(fldObj);
			return fldObj ? field.create(fldObj, that) : null;
		}
The above is the code for getSublistField, notably it uses nlapiGetLineItemField, which has the line as optional if you can trick
validateAndGetOneBasedIndex
, then you can get the field
Copy code
function validateAndGetOneBasedIndex(index, method, indexUpperLimit)
	    {
	        if (isNaN(index))
	            return index;
	        else
	            index = parseInt(index, 10);

	        if (index < 0 || (indexUpperLimit !== undefined && index >= indexUpperLimit))
	        {
	            throw error.create({name: error.Type.INVALID_SUBLIST_OPERATION, message: method});
	        }
	        else
	        {
	            return index + 1;
	        }
	    }
The code is not very good at validating, so it is possible to trick it
l
battk I tried the paginit suggestion
Copy code
var objField11
        var defaultField11
        function pageInit(scriptContext) {
            scriptContext.currentRecord.insertLine({
                sublistId: 'cust_segment_rules_sublist_default',
                line: 0,
                ignoreRecalc: true
            });

            objField11 = scriptContext.currentRecord.getSublistField({
                sublistId: `cust_segment_rules_sublist_default`,
                fieldId: 'custrecord_st_segment_default',
                line: 0
            });
            defaultField11 = scriptContext.currentRecord.getSublistField({
                sublistId: `cust_segment_rules_sublist_default`,
                fieldId: `custpage_default_value_default`,
                line: 0
            });

            scriptContext.currentRecord.removeLine({
                sublistId: 'cust_segment_rules_sublist_default',
                line: 0,
                ignoreRecalc: true
            });
        }
Copy code
defaultField11.removeSelectOption({
        value: null,
    });

     defaultField11.insertSelectOption({
                            value: option,
                            text: option
                        });
This worked Great!!!!!!!! Thank you battk 👏👏👏👏👏🎯