Help needed when value in referance field changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 06:57 PM
I have a form on incident table that has a field named 'Region' (referance field with options as US, EU, APAC). There is a UI action button 'Resolve' that shows on this form.
(1) If the user selects US & EU, The resolve UI action should be shown
(2) If the user selects APAC, the resolve UI action button should not be shown.
How to achieve part (2) from client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 08:22 PM
Hello @Snehal13
This Community link may help...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 08:03 PM
That code is jQuery which is DOM manipulation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 09:29 PM - edited 09-07-2023 09:30 PM
Hi,
Please try below onChange client script for the Region field (I have tried with the Assignment group field, you can change it according to your requirements. I have tried if assignment group is Database then Resolve button need to be hide, if assignment group is anything else apart from Database, then Resolve button need to be show). But you need to uncheck Isolate script checkbox to run the DOM Manipulation code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var uiActionButton = document.getElementById('resolve_incident'); // 'resolve_incident is action name of UI Action button
if(g_form.getValue('assignment_group') === '287ee6fea9fe198100ada7950d0b1b73'){ // if assignment group is Database
uiActionButton.style.display = "none";
}
else{
uiActionButton.style.display = "block";
}
}
or you can try this code also
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(g_form.getValue('assignment_group') === '287ee6fea9fe198100ada7950d0b1b73'){ // assignment group is Database
var btn = $$('BUTTON').each(function(item){
if(item.innerHTML.indexOf('Resolve') > -1){ // 'Resolve' is name of the UI Action button
item.hide();
}
});
}
else{
var btn = $$('BUTTON').each(function(item){
if(item.innerHTML.indexOf('Resolve') > -1){ // 'Resolve' is name of the UI Action button
item.show();
}
});
}
}
Please mark my answer helpful if it works.
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 07:38 PM
Not want to do DOM Manipulation to hide UI action based on value change in a referance field. Any other recommended way ? The UI action condition runs on server side and my requirement is to hide UI action when referance field value changes.