1
votes

Below are the sub records for Customer using currentRecord.getSublists();

I'm getting like ["currency","creditcards","grouppricing","itempricing","systemnotes","access","activeworkflows","recmachcustrecord2","recmachcustrecord_2663_parent_cust_ref","subscriptions"]

for recmachcustrecord2 sub record. I want to store into another variable like

    var sublistFieldValue = currentRecord.getSubrecord({
        fieldId: 'recmachcustrecord2'
    });

but I'm getting like

"type":"error.SuiteScriptError","name":"FIELD_1_IS_NOT_A_SUBRECORD_FIELD","message":"Field custrecord_acceptable_min_shelf_life is not a subrecord field.","stack":["anonymous(N/serverRecordService)","onAfterSubmit(/SuiteScripts/cus.js:38)"],"cause":{"type":"internal error","code":"FIELD_1_IS_NOT_A_SUBRECORD_FIELD","details":"Field custrecord_acceptable_min_shelf_life is not a subrecord field.","userEvent":"aftersubmit","stackTrace":["anonymous(N/serverRecordService)","onAfterSubmit(/SuiteScripts/cus.js:38)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}

Thanks in Advance!

2

2 Answers

6
votes

currentRecord.getSublists() is used to fetch list of sublists on current record and sublist are not subrecord. As per your example you need to use getSublist as follows

sublist = currentrecord.getSublist({ sublistId: 'recmachcustrecord2' });

Sublist represents records so you can directly edit/read data from sublist itself. To read and edit fields in a sublist you can use the following

// to read values from sublist
currentrecord.getSublistValue({ sublistId: 'recmachcustrecord2', fieldId: SUBLIST_FIELD_ID, line: LINE# });
// to edit values
currentrecord.selectLine({ sublistId: 'recmachcustrecord2', fieldId: SUBLIST_FIELD_ID, line: LINE# });
currentrecord.setCurrentSublistValue({ sublistId: 'recmachcustrecord2', fieldId: SUBLIST_FIELD_ID, line: LINE#, value: VALUE });
currentrecord.commitLine({ sublistId: 'recmachcustrecord2' });
4
votes

What you're looking at are sublists, not subrecords. You'll want to retrieve the values from the sublist by using the currentRecord selectLine and getCurrentSublistValue methods.