put together a Create WO button from Lot Number As...
# general
a
put together a Create WO button from Lot Number Assembly item. If I was to create a WO and manually put in the assembly it would auto fill class and department.. now the create WO button will pull the Assembly item over correctly but won't fill in the class and department.. I think it's pulling correctly but not filling..you can see below it is pulling the correct fields but not filling in where they should app.netsuite.com/app/accounting/transactions/workord.nl?compid=458282&location=&assemblyitem=2408&department=Production+%3A+Coatings&class=Work+In+Process+%3A+Permanent+Sealer&whence=
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/redirect', 'N/record', 'N/search', 'N/log'], (redirect, record, search, log) => {

  const onRequest = (context) => {
    const request = context.request;
    const itemId = request.parameters.itemId;

    if (!itemId) {
      context.response.write('Error: Missing item ID');
      return;
    }

    try {
      // Look up the Department, Class, and Location by TEXT (name/label)
      const itemFields = search.lookupFields({
        type: search.Type.ITEM,
        id: itemId,
        columns: ['department', 'class', 'location']
      });

      const departmentName = itemFields.department?.[0]?.text || '';
      const className = itemFields.class?.[0]?.text || '';
      const locationName = itemFields.location?.[0]?.text || '';

      log.debug('Redirecting to Work Order with', {
        itemId,
        departmentName,
        className,
        locationName
      });

      redirect.toRecord({
        type: record.Type.WORK_ORDER,
        isEditMode: true,
        parameters: {
          assemblyitem: itemId,
          department: departmentName,
          class: className,
          location: locationName
        }
      });

    } catch (e) {
      log.error('Error in Suitelet redirect', e);
      context.response.write('An error occurred while creating the Work Order.');
    }
  };

  return { onRequest };
});
Slack Conversation