This topic contains 6 replies, has 0 voices, and was last updated by starlingMark 7 years, 7 months ago.
-
AuthorPosts
-
March 28, 2017 at 8:46 am #1013
starlingMarkI’m running a client script for some validation before the save of an Assembly Build. I am validating some information about the lot number/quantity chosen, so I need to get the inventorydetail subrecord from the body field.
Here is a snippet of code:
Code:
var inventoryDetailSubrecord = scriptContext.currentRecord.getSubrecord({ fieldId: ‘inventorydetail’ });
console.log(JSON.stringify(inventoryDetailSubrecord));var lineCount = inventoryDetailSubrecord.getLineCount({ sublistId: ‘inventoryassignment’ });
My console shows the proper subrecord information. However, the line where I try to get the lineCount throws an error “referenceError: options is not defined”.If I try the same code in SS1 from the console it works properly.
Anyone else seen this or know how to get around this?
This is a cached copy. Click here to see the original post. -
March 30, 2017 at 3:07 pm #1014
ssilveri77I was using this in SS2.0 from fulfilment…
sr = itf.getSublistSubrecord({ sublistId : ‘item’,
fieldId : ‘inventorydetail’ ,
line : 0});
I never completed the rest of the testing , but I would get referenceError when using the incorrect method. try getSublistSubrecord
-
March 31, 2017 at 4:47 am #1015
starlingMarkssilveri77 The getSublistSubrecord method is only for getting a subrecord from a sublist field. In this instance I need the one from the body field.
In either case, I can retrieve the subrecord – the real issue is when I call getLineCount.
-
March 31, 2017 at 9:28 am #1016
david.smithtry adding this:
var inventoryDetail = scriptContext.currentRecord();
var inventoryDetailSubrecord = inventoryDetail.getSubrecord({ fieldId: ‘inventorydetail’ });
var lineCount = inventoryDetail.getLineCount({ sublistId: ‘inventoryassignment’ });
-
March 31, 2017 at 9:45 am #1017
starlingMarkdavid.smith Thanks for the suggestion. This returns a value of -1 for the line count. However, isn’t this snippet trying to get the number of lines on the inventoryassinment sublist on the assembly build record instead of the inventory detail subrecord?
david.smith replied on 03/31/2017, 10:00 AM: Sorry. I believe you’re correct. I think you need to use the first line to get the currentRecord. I haven’t tested this.
var lineCount = inventoryDetailSubrecord.getLineCount({ sublistId: ‘inventoryassignment’ });
-
April 4, 2017 at 9:54 am #1018
ssilveri77I took the following code and ran it in the debugger with scrip version set to 2.0. It worked fine and gave me a line count of 4 which is correct. Check of the record is loaded in deferred or non deferred mode… Are you doing a client side or server side script
Code:
require([ ‘N/record’],function(record) {
try {
var rec = record.load( {type : record.Type.ASSEMBLY_BUILD,
id : 557560 });var inventoryDetailSubrecord = rec.getSubrecord({ fieldId: ‘inventorydetail’ });
var lineCount = inventoryDetailSubrecord.getLineCount({ sublistId: ‘inventoryassignment’ });
var sublistFieldValue = rec.getSublistValue({
sublistId: ‘component’,
fieldId: ‘item’,
line: 0
});
} catch (e) {
var obj = JSON.parse(e)
log.debug(‘type ‘,obj.type);
log.debug(‘name ‘,obj.name);
log.debug(‘message ‘,obj.message);
log.debug(‘details ‘,obj.cause.details);throw obj.message;
}var recId = rec.id;
}); -
April 13, 2017 at 6:57 am #1019
starlingMarkSorry for the long delay here. I am doing mine on create, client-side, fired on the save record event. The record is indeed in dynamic mode and still presents the original error.
-
AuthorPosts
You must be logged in to reply to this topic.