I have a requirement to show the form section tab only when it is submitted from a particular Recor

Sprankle
Tera Contributor

I have a requirement to show the form section tab only when it is submitted from a particular Record producer ,created Display Business rule and Onload client script its is working but after refreshing the page twice then it is showing  the tab section. Need suggestion

6 REPLIES 6

@Sprankle 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Sprankle 

 

Fix Options

Option 1: Use onDisplay Business Rule directly for section visibility

Instead of passing only a flag to scratchpad, you can directly push a UI Policy / setSectionDisplay logic inside the onLoad script but controlled by g_scratchpad (ensuring it’s always available on first load).

Update Display BR like this:

 

 
(function executeRule(current, g_scratchpad)
{
var rpSysId = gs.getProperty('port');
var gr = new GlideRecord("sc_item_produced_record");
gr.addQuery("task", current.sys_id);
gr.query();
g_scratchpad.showSelfTab = false;
if (gr.next() && gr.producer == rpSysId)
{
g_scratchpad.showSelfTab = true;
}
})(current, g_scratchpad);

 

Then your Client Script remains:

 

 
if (g_scratchpad.showSelfTab)
{
g_form.setSectionDisplay('self_', true);
// show
} else
{
g_form.setSectionDisplay('self_', false);
// hide
}

This ensures the scratchpad flag is always ready on first load.

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

ď”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ď”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/