Ivan
Ivan

Reputation: 35

Is there a way to find out if current Netsuite record is a subrecord of another record inside suitescript?

The problem:
I'm working on client script (pageInit entry) for Inventory Detail record (id: inventorydetail), but I need this script to run ONLY when this record (inventorydetail) is being loaded from Item Receipt record (not Item Fulfillment or any other).

Is there a way to get 'super' record type during script execution or can I specify this logic (run for inventory detail in context of item receipt only) in Ntesuite UI?

Note:
Script will have to change (or at least set default) values inside inventory detail form before any user changes or, ideally, it should catch user changes and perform some actions. SuiteScript2.0 preferably.

Upvotes: 1

Views: 2735

Answers (3)

Ivan Posadas
Ivan Posadas

Reputation: 1

You can use a SS 1.0 command on the script attached to the Inventory Detail making reference to the parent (window):

parent.nlapiGetRecordType()

Upvotes: 0

Charl
Charl

Reputation: 827

An alternative solution would be to make use of a user event script.

Inventory Detail is not considered a record on NetSuite and you can therefore not apply a user event script to it. It is a subrecord and you can think of it as a field with multiple attributes.

You might have to apply your script as a user event script to the Item Receipt record. Your script will have to update the inventory detail on the "BEFORE LOAD FUNCTION" user event. This would mean that the default values will be populated on the inventory detail, but will not be saved to the database until the user saves the Item Receipt record.

In SuiteScript 2, get the inventory detail subrecord for each line on your ItemReceipt and change the values as you wish:

var inventoryDetailRecord = itemReceipt.getSublistSubrecord({
      sublistId: 'item',
      fieldId: 'inventorydetail',
      line: i
    });

    inventoryDetailRecord.setSublistValue({
      sublistId: 'inventoryassignment',
      fieldId: 'issueinventorynumber',
      value: serialId,
      line: 0
    });

The downside to this solution is that you'll be populating data on a subrecord, even if the subrecord is not viewed - this might not be ideal, depending on what you want to do.

Upvotes: 0

Purna Gadde
Purna Gadde

Reputation: 54

I am not sure if NetSuite has an API for it. Will have to check. But if there is no NetSuite API we can achieve it through JavaScript DOM. You can use window.parent.location.path in which you will get the reference off from which record the subrecord has been opened.

Upvotes: 3

Related Questions