UI Policy - get the reference field value (not working)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 03:28 PM
Hi All,
I need help to get the reference field "model category" value on to alm_hardware table.
I created a UI policy script but it is working partially because it's hiding the tabs(form section) based on role and not on type of records.I would like to hide the tabs based on role and type of model category. Kindly review my scripts, I have multiple role and multiple category.
function onCondition(){
var gr = g_form.getReference('model_category');
if(g_user.hasRole('service_desk') && gr.category_type == 'desk') {
g_form.setSectionDisplay('financial', true);
g_form.setSectionDisplay('activities', true);
}
//else if (g_user.hasRole('itil') && gr.u_category_type == 'service'){
else{
g_form.setSectionDisplay('financial', false);
g_form.setSectionDisplay('activities', false);
}
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2022 05:49 PM
function onLoad() {
var gr = g_form.getReference('model_category');
if(gr.category_type == 'Computer' && g_user.hasRole('itil'); {
g_form.setSectionDisplay('financial', false);
}
}
This worked for me

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-23-2022 04:22 AM
great! now build a logic around it
1. Rewrite the script to use the callback part and build the logic in the second function (this simply guarantees the form will not wait with loading after everything is finished)
function onLoad() {
g_form.getReference('model_category', hideOrDisplaySections);
}
function hideOrDisplaySections(gr) { // reference is passed into callback as first arguments
if(gr.getValue('category_type') == 'Computer' && g_user.hasRole('itil') {
g_form.setSectionDisplay('financial', false);
}
}
Just be sure you're using correct fields from the [cmdb_model_category] table. I am surprised you have a field called category_type, custom fields normally start with u_
Let me know if you need any further help or mark my answer as correct