Catalog Client Script to make a variable not visible and not mandatory depending on custom column
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:44 AM
We are using the Product Lifecycle table to track all of our hardware and software for Enterprise Architecture. I have a catalog item for requesting non-core software installations that asks for product and department. I need to have the department field not visible or mandatory if the product is enterprise-wide. Here is what I have right now.
Thanks,
Erin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:51 AM
Hello @erin-marie
Why are you using client script to begin with ?
Why not UI policy, with just one you can operate both visible and mandatory. And conditions you can add whatever you want.
What is the hurdle here with ui policy ?
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:57 AM
I am probably overthinking it. I need to take the product from the catalog form. And then do a lookup on a table to see if it is enterprise which is another field on the lifecycle table; can I do all of that through UI policy?
form variable: sc_sw_noncore_trmproduct
table: sn_apm_trm_standards_product_lifecycle
field name: trm_product
second field name: u_enterprise_wide
if enterprise wide, make catalog form fields visible and mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 10:03 AM
Hello @erin-marie
Okeh so you need to check whether it's enterprise or not on a different table. So this product should be a reference field and you can easily dot walk and check whether it's enterprise or not - correct ?
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOw
NeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 10:21 AM
Hello @erin-marie
If what I am understanding is correct. Please use below script for Script include - Make sure to check Client Callable.
var TRMProductHelper = Class.create();
TRMProductHelper.prototype = {
initialize: function() {},
getEnterpriseStatus: function(trmProduct) {
if (!trmProduct) {
return false; // Return false if no product is provided
}
var gr = new GlideRecord('sn_apm_trm_standards_product_lifecycle');
gr.addQuery('trm_product', trmProduct);
gr.query();
if (gr.next()) {
return gr.u_enterprise_wide == true; // Returns true/false
}
return false;
},
type: 'TRMProductHelper'
};
Below in On change Client scripts - Make sure to mark UI TYPe to - All and variable name to - "sc_sw_noncore_trmproduct"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Call the Script Include to get the enterprise-wide status
var ga = new GlideAjax('TRMProductHelper');
ga.addParam('sysparm_name', 'getEnterpriseStatus');
ga.addParam('sysparm_trmProduct', newValue);
ga.getAnswer(function(response) {
if (response == 'true') {
g_form.setVisible('sc_sw_noncore_trmdepartment', false);
g_form.setMandatory('sc_sw_noncore_trmdepartment', false);
} else {
g_form.setVisible('sc_sw_noncore_trmdepartment', true);
g_form.setMandatory('sc_sw_noncore_trmdepartment', true);
}
});
}
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOw
NeEISQCY