We have some limitation to fetch the price levels and quantity levels for the item with quantity pricing. So, we have created a user event script to set the special price object in the item record as shown below.

The value in the field will be set when we edit and save the item record after any update.
The user event script
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
/*******************************************************************************
* CLIENTNAME:Pure Care
*
*
* USER EVENT SCRIPT FOR SETTING UP SPECIAL PRICE OBJECT
*
*
* **************************************************************************
* Date : 12/06/2022
*
* Author: JOBIN AND JISMI IT SERVICES LLP
* Shyma Ali
*
* Script Description :
*
* Date created :12/25/2023
*
* REVISION HISTORY
*
*
*
******************************************************************************/
define(['N/search', 'N/runtime'],
(search, runtime) => {
/**
*@description Function to set special Price oBJECT.
*/
const setSpecialPrice = (itemRecord, itemInternalId) => {
var itemRecord = itemRecord
var internalId = itemInternalId
var priceID = 'price1';
var quantityLevels = itemRecord.getMatrixHeaderCount({
sublistId: priceID,
fieldId: 'price',
line: 1
});
var quantityLevels = [];
var specialPriceObj = [];
var quantityPrice = {};
var itemSearchObj = search.create({
type: "item",
filters:
[
["internalid", "anyof", internalId],
"AND",
["formulatext: CASE WHEN {pricing.pricelevel} = 'special price' THEN 1 ELSE 0 END", "is", "1"]
],
columns:
[
search.createColumn({
name: "pricelevel",
join: "pricing",
label: "Price Level"
}),
search.createColumn({
name: "quantityrange",
join: "pricing",
label: "Quantity Range"
}),
search.createColumn({
name: "unitprice",
join: "pricing",
label: "Unit Price"
})
]
});
var searchResultCount = itemSearchObj.runPaged().count;
if (searchResultCount > 1) {
itemSearchObj.run().each(function (result) {
let quantityRange = result.getValue({
name: "quantityrange",
join: "pricing",
label: "Quantity Range"
});
quantityLevels.push(quantityRange);
var specialPrice = result.getValue({
name: "unitprice",
join: "pricing",
label: "Unit Price"
});
specialPriceObj.push(specialPrice);
quantityPrice[quantityRange] = result.getValue({
name: "unitprice",
join: "pricing",
label: "Unit Price"
});
return true;
});
}
quantityPrice = JSON.stringify(quantityPrice);
log.debug('quantityPriceafter', quantityPrice);
return quantityPrice;
}
/**
* Defines the function definition that is executed before record is submitted.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @since 2015.2
*/
const beforeSubmit = (scriptContext) => {
try {
const newRecord = scriptContext.newRecord;
const itemInternalId = newRecord.getValue({
fieldId: 'internalid'
});
log.debug("specialPrice3", itemInternalId);
const specailObject = setSpecialPrice(newRecord, itemInternalId)
newRecord.setValue({
fieldId: 'custitem_special_price_obj',
value: specailObject
});
} catch (error) {
log.error("Error @beforeSubmit", error);
}
}
return { beforeSubmit }
})
;