- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 12:13 PM - edited 05-22-2023 12:40 AM
Hi all,
I have a requirement in the catalog item.
There is a table where the data is stored. And in the catalog item, there are two fields.
Eg.: When "Joshua Tree" is selected in name, the capacity of that name is 32 according to the table data. So, in the capacity field, if the user enters the number more than 32, then it should show some alert and clear the value.
Same for "Emerald Bay". If "Emerald Bay" is selected in name, the capacity of that name is 28 according to the table data. So, in the capacity field, if the user enters the number more than 28, then it should show some alert and clear the value.
CATALOG CLIENT SCRIPT
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("autoPopulateDetails"); //script include name
ga.addParam("sysparm_name", "getCapacity"); //function name
ga.addParam("sysparm_sysid", newValue); //paramter pass to server
ga.getXMLAnswer(setdetails); //callback funtion
var table_ref = g_form.getReference('u_room_name', getCapacity); //catalog room name backend value
function getCapacity(table_ref) {
var name_capacity = table_ref.u_capacity; //u_capacity is custom table Capacity Field back end value
if(newValue >= name_capacity) {
alert("maximum capacity exceeded");
g_form.clearValue('please_confirm_the_number_of_people_that_are_going_to_attend_your_meeting_on_site');
}
}
}
SCRIPT INCLUDE
var autoPopulateCapacity = Class.create();
autoPopulateCapacity.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCapacity: function() {
var val;
var sysid = this.getParameter("sysparm_sysid");
var grUsr = new GlideRecord("u_conference_room");//table name
grUsr.addQuery("sys_id", sysid);//filters with sysid
grUsr.query();
if (grUsr.next()) {
val = grUsr.u_capacity; //field name to get
return val;
}
},
type: 'autoPopulateCapacity'
});
How can I achieve this? Thanks in advance!
@Ankur Bawiskar @Community Alums @Karan Chhabra6 @Pradeep Sharma @Allen Andreas @Chuck Tomasi @Jaspal Singh @Musab Rasheed @Pavankumar_1 @Manmohan K
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 12:57 PM
Hi @2022_ServiceNow ,
Please try the below code.
Create an OnChange catalog client script in your catalog item on a variable capacity.
Code:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 01:32 AM
update as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var table_ref = g_form.getReference('u_room_name', getCapacity); //name is catalog name variable backend value
}
function getCapacity(table_ref) {
var name_capacity = parseInt(table_ref.u_capacity); //u_capacity is custom table Capacity Field back end value
if(parseInt(newValue) >= name_capacity) {
alert("maximum capacity exceeded");
g_form.clearValue('please_confirm_the_number_of_people_that_are_going_to_attend_your_meeting_on_site');
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 12:57 PM
Hi @2022_ServiceNow ,
Please try the below code.
Create an OnChange catalog client script in your catalog item on a variable capacity.
Code:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 09:00 PM
Thank you for the response.
I tried with the above script. But it is not working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var table_ref = g_form.getReference('u_room_name', getCapacity); //name is catalog name variable backend value
function getCapacity(table_ref) {
var name_capacity = table_ref.u_capacity; //u_capacity is custom table Capacity Field back end value
if(newValue >= name_capacity) {
alert("maximum capacity exceeded");
g_form.clearValue('please_confirm_the_number_of_people_that_are_going_to_attend_your_meeting_on_site');
}
}
}
u_room_name - name field backend value in the custom table
u_capacity - capacity field backend value in the custom table
Is it not required to add Script include here to reference the custom table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 01:32 AM
update as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var table_ref = g_form.getReference('u_room_name', getCapacity); //name is catalog name variable backend value
}
function getCapacity(table_ref) {
var name_capacity = parseInt(table_ref.u_capacity); //u_capacity is custom table Capacity Field back end value
if(parseInt(newValue) >= name_capacity) {
alert("maximum capacity exceeded");
g_form.clearValue('please_confirm_the_number_of_people_that_are_going_to_attend_your_meeting_on_site');
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2023 01:41 AM - edited 05-22-2023 01:42 AM
I made the changes, but it is not working. To achieve this script include is not necessary? What other changes I have to make here. Can you please let me know?
The capacity depends on the name selected.