Display the price of the model in the summary of the Order guide from the pc_vendor_cat_item

madhusagar
Tera Contributor

Hi All,

How can I fetch the price value of a model from the pc_vendor_cat_item table and automatically populate that price in the Order Guide summary in ServiceNow when the selected model in the category matches a record in pc_vendor_cat_item?

 

Thanks & Regards,

Madhu.

1 REPLY 1

NavinAgarwal
Mega Guru

Hi @madhusagar ,

 

This requires below customization and I have included sample code for you to implement:

  • Client-side script to detect the model selection.
  • GlideAjax call to a server-side Script Include to query pc_vendor_cat_item for the price.
  • Client-side update of the Order Guide summary variable.

Step 1: Create a Script Include (Server-side)

// Name: GetVendorCatItemPrice
// Accessible from client: Yes
var GetVendorCatItemPrice = Class.create();
GetVendorCatItemPrice.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getPriceByModel: function() {
var modelName = this.getParameter('sysparm_model_name');
if (!modelName) {
return '';
}

var gr = new GlideRecord('pc_vendor_cat_item');
gr.addQuery('model.name', modelName); // Adjust field if needed
gr.query();

if (gr.next()) {
return gr.price.toString(); // Ensure price is returned as string
}
return '';
}

});

 

Important points:

  • Make sure Client Callable is checked.
  • Adjust the query field (model.name) if your table uses a different reference field.
  • Ensure the price field exists in pc_vendor_cat_item.

 

Step 2: Add a Catalog Client Script (Client-side)
This will run when the model variable changes in the Order Guide.

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

// Call Script Include via GlideAjax
var ga = new GlideAjax('GetVendorCatItemPrice');
ga.addParam('sysparm_name', 'getPriceByModel');
ga.addParam('sysparm_model_name', g_form.getDisplayValue('model')); // 'model' is the variable name
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('price', response); // 'price' is the variable in the Order Guide summary
} else {
g_form.setValue('price', 'N/A');
}
});
}

 

Important points:

  • Replace 'model' with your actual variable name for the model selection.
  • Replace 'price' with the variable name in the Order Guide summary where you want the price displayed.
  • This script should be Catalog Client Script with Type = onChange.

Step 3: Ensure the Price Variable is in the Order Guide Summary
Create a read-only variable in the Order Guide called price.
Mark it as Visible in Summary so it appears in the final review step.


How It Works:

  • User selects a model in the Order Guide.
  • onChange client script triggers.
  • GlideAjax calls the Script Include.
  • Script Include queries pc_vendor_cat_item for the matching model.
  • Price is returned and set in the price variable.
  • Price appears in the Order Guide summary automatically.

 

If you found my response helpful, could you please mark it as ‘Accept as Solution’ and ‘Helpful’? This small action goes a long way in helping other community members find the right answers more easily and supports the community.

 

Regards,
Navin