The Assembly item was successfully created by suing the script, but it was not getting displayed on the website even though its ‘display in website’ ID is true and the inactive field is false.
The assembly items created were categorized as “uncategorized,” which results in them being hidden from the website, which was due to PCV (Personalized Catalog View) available on the domain. This happens despite the items being available in the category, which is displayed for all users.
Solution for the issue:
- Adjust the default website visibility level:
- Change the default “Hide Fully” website visibility level to “Display Fully.”
- This ensures that newly created items (including uncategorized ones) will be visible on the website by default.
- Create a Custom Field for Website Display Control:
- Add a custom item field, such as “Display Assembly Item on Website,” to manage item visibility on the website.
- This field will act as a toggle to control whether an item is displayed on the website.
- Enable the Field for Items to Display:
- Set the “Display Assembly Item on Website” field to enabled for all items that need to be visible on the website.
- For items categorized as “uncategorized” or items you want to hide, set the field to disabled.
- Automated Field Setting during Item Creation:
- During the creation of new items, ensure the field is enabled by default if the item should be displayed on the website.
- This allows immediate control over visibility without additional manual intervention.
- This approach simplifies the management of item visibility on the website.
- It ensures that only the intended items are displayed while hiding unwanted ones.
- The custom field provides a clear, consistent method for controlling item visibility directly within the item record.
By implementing this solution, you can avoid having uncategorized items unintentionally hidden from the website while maintaining flexibility to manage the visibility of specific items.
The code for creating the assembly item using script with limited fields
var assemblyItem = nlapiCreateRecord('lotnumberedassemblyitem');
// Set essential fields
assemblyItem.setFieldValue('itemid', 'My Assembly Item'); // Name of the assembly item
assemblyItem.setFieldValue('displayname', 'My Assembly Item'); // Display Name
assemblyItem.setFieldValue('isinactive', 'F'); // Ensure the item is active
assemblyItem.setFieldValue('isonline', 'T'); // Display in Website: true
assemblyItem.setFieldValue('storedisplayname','My Assembly Item');
assemblyItem.selectNewLineItem('member');
assemblyItem.setCurrentLineItemValue('member', 'item', '62558'); // Internal ID of the member item
assemblyItem.setCurrentLineItemValue('member', 'itemsource', 'STOCK'); // Item source
assemblyItem.setCurrentLineItemValue('member', 'linenumber', '1'); // Line number
assemblyItem.setCurrentLineItemValue('member', 'memberdescr', 'ALWAYS 1Ea<br>-MUST SELECT A BELOW OPTION-<br>1. CTG-MFG-BIGBLUE-UP/DOWN-OH<br>2. CTG-MFG-LITTLEBLUE-UP/DOWN-OH<br>3. CTG-MFG-GREENMACH-UP/DOWN-OH'); // Member description
assemblyItem.setCurrentLineItemValue('member', 'memberkey', '115826'); // Member key (unique identifier)
assemblyItem.setCurrentLineItemValue('member', 'memberunit', '1'); // Member unit
assemblyItem.setCurrentLineItemValue('member', 'quantity', '.001'); // Quantity
assemblyItem.setCurrentLineItemValue('member', 'sitemtype', 'InvtPart'); // Item type
assemblyItem.commitLineItem('member'); // Commit the line to save the member details
// Save the record
var recordId = nlapiSubmitRecord(assemblyItem);
console.log('Assembly Item Created: ' + recordId);