Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set price of service catalog item using a client script

PranavSuj96
Mega Expert

Hello, 

I have a service catalog item which is used to rent cars. The customers can pick an available car through a reference variable that references my car inventory table. Each car record on the car inventory table has a price field. The price doesn't show or change. I tried to use an info message to display the price but the the message is blank. Any help would be appreciated!!

 

 

 

This is my current script:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.addInfoMessage(g_form.getValue('price'));
g_form.addInfoMessage('hello. script is running for dynamic price');
var car = g_form.getReference('cars',findPrice);

function findPrice(car) {
g_form.setValue('price',car.u_price_2);
}

insurance = g_form.getValue('u_insurance');
if (insurance == 'yes') {
g_form.setValue('price',g_form.getValue('price')+insurance);
}
}

2 REPLIES 2

Abdul Wahid
Kilo Expert

i didn't work with getReference .. sorry about that..better you can use glide record and fetch the price for the particular car from the table ...just my suggestion

 

var carValue=g_form.getValue('car_variable_name');

var gr = new GlideRecord('your_table');
gr.addQuery('car', carValue);
gr.query(myCallbackFunction); //Execute the query with callback function

//After the server returns the query recordset, continue here
function myCallbackFunction(gr){
   while (gr.next()) { //While the recordset contains records, iterate through them
      console.log(gr.price);
   }
}

 

if you really wanted to use getReference ..refer this link 

 

https://www.servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/

 

thanks

abdul

how do I set the price of the catalog? I'm able to successfully get the price of the car.