vuejs3dynamics-business-centralbusinesscentral

How to populate the Service Item Worksheet Lines?


I’m new to Business Central and I’m trying to figure out which API I should use to populate the Service Item Worksheet subform (Lines). I’ve already tried Service Item Lines, Service Lines, and Lines (5902), but none of them seem to be correct.

service item worksheet in business central

This is what I tried so far:

const _createServiceLines = async (serviceOrder, product, serviceItem) => {
  console.log('product', product)

  // Create Service Lines payload for the main product unit
  const payload = {
    body: {
      "Type": "Item",
      "Service_Item_No": serviceItem['Item_No'], // from created order lines
      "No": product.product_id?.itemCode,
      "Document_Type": "Order",
      "Document_No": serviceOrder['No'], // The service order number you created
      "Line_No": 0, // auto-generate
      "Description": product.product_id?.description?.replace(/<[^>]*>/g, '') || '',
      "Quantity": product.quantity || 0,
      "Unit_Price": product.salesPrice || 0,
    }
  }

  console.log('Service Lines Payload:', payload)

  // Create the main Service Lines
  const res = await createServiceLines({ 
    data: payload, 
    config: getBranchConfig.value 
  })

  if (res?.status === 201) {
    const resData = res.data
    console.log('Created Service Lines:', resData)
  } else {
    console.log('Failed to create service lines')
  }
}

Solution

  • ✅ Answer Found – Use Service Lines (5905) API

    To populate the Service Item Worksheet subform (Lines), you should use the Service Lines (5905) endpoint. However, it requires referencing the correct Service_Item_Line_No, which must come from the previously created Service Item Lines (5902).

    Here’s a working example of how to create a Service Line:

    const _createServiceLines = async (serviceOrder, product, serviceItem) => {
      console.log('product', product)
    
      // Create Service Lines payload
      const payload = {
        body: {
          "Service_Item_Line_No": serviceItem['Line_No'], // from created order lines
          "No": product.product_id?.itemCode,
          "Document_Type": "Order",
          "Document_No": serviceOrder['No'], // the service order number you created
          "Type": "Item",
          "Line_No": 0, // auto-generate
          "Description": product.product_id?.description?.replace(/<[^>]*>/g, '') || '',
          "Quantity": product.quantity || 0,
          "Unit_Price": product.salesPrice || 0,
        }
      }
    
      console.log('Service Lines Payload:', payload)
    
      // Create the main Service Lines
      const res = await createServiceLines({ 
        data: payload, 
        config: getBranchConfig.value 
      })
    
      if (res?.status === 201) {
        const resData = res.data
        console.log('Created Service Lines:', resData)
      } else {
        console.log('Failed to create service lines')
      }
    }