This topic contains 6 replies, has 0 voices, and was last updated by starlingMark 7 years, 7 months ago.

  • Author
    Posts
  • #1013

    starlingMark

    I’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.

  • #1014

    ssilveri77

    I 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

  • #1015

    starlingMark

    ssilveri77 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.

  • #1016

    david.smith

    try adding this:

    var inventoryDetail = scriptContext.currentRecord();

    var inventoryDetailSubrecord = inventoryDetail.getSubrecord({ fieldId: ‘inventorydetail’ });

    var lineCount = inventoryDetail.getLineCount({ sublistId: ‘inventoryassignment’ });

  • #1017

    starlingMark

    david.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’ });

  • #1018

    ssilveri77

    I 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;
    });

  • #1019

    starlingMark

    Sorry 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.

You must be logged in to reply to this topic.