Only display the Planning tab for 'Normal' Change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2016 06:37 PM
Hey Community,
I need your help. I am more of a guy that understands and can code rather than a hardcore developer and trying to fill a requirement to Display ONLY the Planning tab on Normal Change and starting to pull my hair out getting it to work. I know its a minor correction that I am missing and at this point feel like I am throwing darts at a board (I'm not a good dart player btw).
SN Version - Helsinki
What I've tried.
Version 1 - Client Script - OnLoad
function onLoad() {
var sections = g_form.getSections();
sections[4].style.display = 'none';
Version 2 - Client Script - OnChange
sections[2].style.display='block'; //Show
else
sections[2].style.display='none'; //Hide
Version 3 & 4 - Client Script - OnChange/onLoad
function onChange() {
//Display Planning Tab on Normal Change records
//Hide the section
var section = $$('span[tab_caption_raw="Planning"]')[0].select('span[id*=section.]')[0];section.show();}
//Hide the tab
$$('.tab_caption_text').each(function(caption) {
if(caption.innerHTML == 'Planning'){
caption.up('.tab_header').show();
}
});
Current Tab Order Attached.
Challenge at hand
1. Create New Change - Normal
2. Display ONLY Planning Tab.
Appreciate the help.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2016 07:22 PM
Hi James,
You can think a slight different way. Rather than focusing on showing only 'Planning' tab in 'Normal' change, you can simply hide other tabs in 'Normal' change. For this you need to write a onChange Client script as you have written. Also you have to consider that along with hiding the other tabs the mandatory fields should be set as non-mandatory.
if(newValue == 'Normal')
{
g_form.clearMandatory('field_1', false);
g_form.clearMandatory('field_2', false);
g_form.setSectionDisplay('tab_1', false); //Provide the tab name
g_form.setSectionDisplay('tab_1', false); //Provide the tab name
You can follow this helpful blog regarding this, Show/Hide Form Section by Name - ServiceNow Guru
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2016 11:30 AM
Hi Amlan,
Appreciate the perspective and tip with mandatory fields. I had not thought of that. I will test it out.
Do you think the reason its not hiding the tabs has anything to do with a syntax error in scripts? I know this should work for requirement but cant for the life of me figure out the reason its not. In the meantime, I'll test it using your method and see if this works.
Cheers,
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2016 03:46 PM
Hi James,
First of all, if you are using Fuji or later version, you do not have to write that section[].style.display. You can simply use g_form.setSectionDisplay('tab_1', false). Please refer the blog which I have mentioned in my last response.
I think, the tab was not getting hide or display=false because of the fields. The field(s) which is available in the tab remains mandatory causing tab to display, even you have written the code to hide.
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-21-2016 11:53 AM
Amlan - Thanks for clarification. I'll make those changes and update once complete.