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

  • Author
    Posts
  • #21931

    k_dunc

    Hi all,

    I'm struggling getting the actual "Serial/Lot Number" value from a Component Item within an Assembly Build. I have no issue getting the Components' Expiry Date

    Code:
    subRecord.getCurrentLineItemValue('inventoryassignment', 'expirationdate')
    and Quantity,

    Code:
    subRecord.getCurrentLineItemValue('inventoryassignment', 'quantity')
    but for some reason, whichever field ID I use to get the Serial/Lot Number just won't work. Can someone please help set me straight.

    Thanks heaps,

    Kirk.
    This is a cached copy. Click here to see the original post.

  • #21932

    Vesku1980

    Hi,

    I struggled with this issue some time ago.

    This solution worked with issue i had, hopefully it will help you too.

    var lineSubRecord = parentRecord.viewLineItemSubrecord('inventory','in ventorydetail',i);

    var bin = lineSubRecord.getLineItemValue('inventoryassignmen t','binnumber',i)

    var inventoryNumber = lineSubRecord.getLineItemValue('inventoryassignmen t','receiptinventorynumber',i)

    Vesku

  • #21933

    k_dunc

    Hi Vesku,

    Thanks for your input. I changed the code to include one sizeable nlapiLogExecution call. I used all manner of IDs that I could think of. Here are the results:issueinventorynumber: this returns the Internal ID of the Inventory Detail
    binnumber: correctly returned the BIN ID
    internalid: returned -1, probably because the record is yet to be submitted
    inventorydetail: returned -1 (as above)
    receiptinventorynumber: returns nothing – obviously wrong
    itemdescription: returns NULL
    externalidstring: returns NULL
    inventorynumber: returns NULL

    So in my opinion, this field value is either an undocumented field ID, or, once I've got the Internal ID of the Inventory Detail, I then need to run some sort of search to get the value. As strange as it is, I can run a Saved Search through NS's UI and it returns the correct value, but for some reason, not through a script?????

    Any further ideas anyone?

  • #21934

    Olivier Gagnon NC

    No, you are correct. NS in its infinite wisdom gives you the internal id, which you must then call a search to translate to the actual lot number.

  • #21935

    k_dunc

    Thanks so much for confirming this stupid 'oversight' Olivier Gagnon NC. As silly as it is, I can get things like Expiry Date and Bin ID directly from here, but I can't get it's actual Serial/Lot Number name. Odd!

    Just to confirm then Olivier, I'm guessing I'll need to do a nlapiLookupField – into which record ID – inventorynumber or inventorydetail?

    I can't find a 'serial number' text field in inventorynumber, so I'm guessing it's something like:

    Code:
    nlapiLookupField('inventorydetail', lotID, 'issueinventorynumber')
    Is that the correct record / field combination?

  • #21936

    Olivier Gagnon NC

    Oh I looked at our code and found something interesting. In BeforeSubmit of Creation (JUST creation), Lot Numbers are returned as text. In all other cases they are returned as internal IDs

    Code:
    function beforeSubmit(context) {
    if (context.type == context.UserEventType.CREATE) {
    var currentRecord = context.newRecord;
    if (isCreatedFromPo(currentRecord)) {

    //Unlike other trigger times, in beforeSubmit of creation, lot numbers are returned as their text values, not their internal IDs
    var lineCount = currentRecord.getLineCount({
    sublistId: 'item'
    });
    for (var i = 0; i < lineCount; i++) {
    var isReceived = currentRecord.getSublistValue({
    sublistId: 'item',
    fieldId: 'itemreceive',
    line: i
    });
    //beforeSubmit on create actually returns all lines, even if you didn't tick them in for reception. So, ignore lines we are not actually receiving
    if (isReceived) {
    var currentSubrecord = currentRecord.getSublistSubrecord({
    sublistId: 'item',
    fieldId: 'inventorydetail',
    line: i
    });
    var subRecordLineCount = currentSubrecord.getLineCount({
    sublistId: 'inventoryassignment'
    });
    for (var j = 0; j < subRecordLineCount; j++) {
    var thisLotText = currentSubrecord.getSublistValue({
    sublistId: 'inventoryassignment',
    fieldId: 'receiptinventorynumber',
    line: j,
    });

    }
    }
    }
    }
    }
    }
    In our case, the other point we needed to check was afterSubmit, so at that point, why bother working with the record at all – we just call a search:

    Code:
    var filters = [{
    name: 'internalid',
    operator: 'IS',
    values: currentRecord.id
    }, {
    name: 'inventorynumber',
    join: 'itemnumber',
    operator: 'STARTSWITH',
    values: prefix
    }].map(function(filt) {
    return search.createFilter(filt);
    });

    var columns = [{
    name: 'inventorynumber',
    join: 'itemnumber'
    }, {
    name: 'internalid',
    join: 'itemnumber'
    }].map(function(col) {
    return search.createColumn(col);
    })

    var searchObj = search.create({
    type: search.Type.ITEM_RECEIPT,
    filters: filters,
    columns: columns
    });

    return searchObj.run().getRange({
    start: 0,
    end: 1000
    });
    }
    This is 2.0 code but the principle should be the same for 1.0

  • #21937

    k_dunc

    Thanks so much for that Olivier. Really appreciate the guidance. For those checking this post in the future, here's what I needed to do (using SuiteScript 1.0):

    Code:
    nlapiLookupField('inventorynumber', lotID, 'inventorynumber');
    once I had the Lot ID.

You must be logged in to reply to this topic.