on change client script is not working for particular catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 01:13 AM
Hi All,
I have written below client script but it is not working for my catalog item it is apply for all catalog item.
kindly let me know what is issue.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var catitem = g_form.getValue("u_catalog_item");
alert(catitem);
//g_form.addInfoMessage("line 9 testing");
if(catitem == '9c9df05597661e500cb57bae2153afe2')
alert("askhr");
{
if(g_form.getValue('state') =="7")
{
g_form.setValue("close_notes", "123455");
g_form.setValue("u_knowledge_article", "no");
g_form.setValue("u_support_type", "desk");
g_form.setValue("u_resolution_code", "Solved (Permanently)");
g_form.setValue("u_via_kb_article", "no");
g_form.setValue("u_via_kb_article", "no");
}
//Type appropriate comment here, and begin script below
}
}
Thanks & Regards
KP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 02:36 AM
you want this script to run only for 1 catalog item right?
then have you given the correct catalog item sysId in the comparison?
also are you sure the section is visible on the form for that catalog item?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 02:40 AM
Hi Ankur,
I have given correct sys_id.
Thanks & Regards
KP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 02:58 AM
is it getting inside the IF?
any other script is setting the fields with other value?
out of 5 fields which fields are not getting set?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2025 06:13 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 01:24 AM
Hi @keval3 ,
Your code is not proper, use below code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Exit the script if it is loading or if the new value is empty
if (isLoading || newValue === '') {
return;
}
// Check if the catalog item matches the specific item
if (g_form.getValue("sys_id") === '9c9df05597661e500cb57bae2153afe2') {
alert("This is the correct catalog item!");
// Perform further checks for specific field values
if (g_form.getValue('state') === "7") {
g_form.setValue("close_notes", "123455");
g_form.setValue("u_knowledge_article", "no");
g_form.setValue("u_support_type", "desk");
g_form.setValue("u_resolution_code", "Solved (Permanently)");
g_form.setValue("u_via_kb_article", "no");
}
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------