Adding custom fields to a Sublist in NetSuite

Hello everyone,

This is my first post here, sorry if I get any conventions wrong.

I’m working on a customers NetSuite system which involves me needs to add a custom field to the “Sales Team” sublist which they have turned on. I have tried the following three aproaches to no avail.’

The sublist needs to be dynamically editable and it is different for each record it is applied to.

I would appreciate any help that can be thought of as I am quite stuck.

  1. Following the guide on the link below, the problem is I simply do not have the “Other Sublist Fields” option available to me, and I cannot see any permissions of how to add it.

https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1515582937.html#:~:text=To%20create%20or%20modify%20custom,type%20the%20field%20applies%20to.

r/Netsuite - Adding custom fields to a Sublist in NetSuite

2) Through a custom scriptlet (UserEventScript BeforeLoad entry point) I have tried to add the fields required that way. This does work and they appear when I go to edit the record, but once I save the record all the fields disappear regardless of if I enter or not. The fields do not appear at all in view mode.

3) Through a custom scriptlet (UserEventScript BeforeLoad entry point) I have created an entirely new sublist and placed it on the page with the required fields. Again this does work and here this appear on the view page, but if I edit and then try to save the record, all of the lines I add to the sublist disappear.

I’ve attached the code for my 3rd solution below. In my second solution I do essentially the same thing except I get out the sublist and add to it rather then creating a new one.

function beforeLoad(context) {
var form = context.form;
if (form.getSublist({id: "custpage_xxxx"})) {
return;
}

var sublist = form.addSublist({
id: "custpage_xxxx",
type: serverWidget.SublistType.INLINEEDITOR,
label: 'Label'
})

sublist.addField({
id: 'custpage_.....',
type: serverWidget.FieldType.SELECT, //any supported TYPE
label: '....',
source: "..."
})

// Add all my fields
}

Rookie Asked on May 11, 2023 in SuiteScript.
Add Comment
1 Answer(s)

Seems like you are on the right track with your third approach. Creating a custom sublist through SuiteScript is a valid solution to adding custom fields to a sublist dynamically.

However, the issue you are facing where the lines you add to the sublist disappear upon saving the record suggests that the sublist is not being properly saved to the record.

To properly save the sublist, you will need to use the sublist.setSublistValue() method within your User Event script. This method allows you to set the values of the fields in the sublist and save them to the record. Here is an example of how you can use this method to save the values of the custom fields in your custom sublist:

 
function beforeSubmit(context) { var newRecord = context.newRecord; var lineCount = newRecord.getLineCount({sublistId: 'custpage_xxxx'}); for (var i = 0; i < lineCount; i++) { var customField1 = newRecord.getSublistValue({ sublistId: 'custpage_xxxx', fieldId: 'custpage_.....', line: i }); // get other custom fields using getSublistValue() // perform any necessary logic or validation on the custom fields // set the values of the custom fields using setSublistValue() newRecord.setSublistValue({ sublistId: 'custpage_xxxx', fieldId: 'custpage_.....', line: i, value: customField1 }); // set values of other custom fields using setSublistValue() } }

 

 

The above code should be placed in the User Event script at the appropriate entry point (in this case, beforeSubmit). The newRecord object is used to get and set the values of the fields in the sublist. In this example, the getSublistValue() method is used to retrieve the values of the custom fields, perform any necessary logic or validation, and then the setSublistValue() method is used to set the values of the custom fields on the sublist.

Make sure to adjust the field IDs and sublist IDs in the code to match your custom fields and sublist ID. Also, make sure to add any necessary validation or logic to ensure the data is properly saved to the record.

I hope this helps you resolve your issue!

Best,

TROY OLTMANNS 

NETSUITE TECHNICAL ARCHITECT

(p) 949.238.6900

(f)  949.271.4635

www.TREVERA.COM

Check out our open opportunities at: Trevera Opportunities

 

 

 

 

 

Beginner Answered on May 11, 2023.

Thank you so much for your prompt response!

I have now implemented this! It is still not working though. I am getting the same problem and now also I am being taken back to the NetSuite home page every time I save the record. Then when I go back and check the lines are not present.

This is what I have put into my script, do you have any further advice?

const FIELDS = [........]
function beforeSubmit(context) {
    var newRecord = context.newRecord;
    var lineCount = newRecord.getLineCount({sublistId: 'custpage_custsublist_salesteam'});
    for (var i = 0; i < lineCount; i++) {
        for (var j = 0; j < FIELDS.length; j++) {
            var customFieldValue = newRecord.getSublistValue({
                sublistId: 'custpage_custsublist_salesteam',
                fieldId: FIELDS[j],
                line: i
            });
            newRecord.setSublistValue({
                sublistId: 'custpage_custsublist_salesteam',
                fieldId: FIELDS[j],
                line: i,
                value: customFieldValue
            });
        }
    }
    return true;
}
on May 11, 2023.

can you describe the code, tell us what you are attempting to do

on May 12, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor