Show/hide container start variable depending on variable choice in front end in a record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 02:33 AM - edited 03-20-2025 03:01 AM
Hello guys!
I wonder if there is any way to show/hide display title of a Container start in a record producer, in front-end? The end user should see the title of the Container start if a certain checkbox is true in the form, otherwise it shoudl be hidden.
I am trying to show/hide with a client script, but it does not work. It the title remains static in the form in front end. Does it have something to do with the variable type? Or can it be achieved in some other way?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Hämta referens till container start variabeln
var containerStart = g_form.getControl('organisational_placement_container_start');
// Visa eller dölj baserat på checkboxens värde
if (newValue) {
containerStart.style.display = 'block';
} else {
containerStart.style.display = 'none';
}
}
As you see in illustration above, the idea is that the title "Organisatorisk placering" (container start variable( is made visible when end user has checked 'Placering i organisationsstrukturen' under 'Select type of information to change?' here.
Why this is important is because i want to be able to have sections in back end:
Thank you in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 03:10 AM - edited 03-20-2025 03:14 AM
Hi @ronro2 ,
You can use g_form.setVisible("variable_name",true) -> to show and g_form.setVisible("variable_name",false) -> Hide
Create on Change client script on field check box.
if(newValue =="true")
{
g_form.setVisible("variable_name",true);
}
else
{
g_form.setVisible("variable_name",false);
}
If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.
Regards,
Rohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 03:10 AM
you will have to use DOM manipulation for this which is not recommended
You need to find out the sys_id of the container and then use:
Ensure Isolate Script = False for your client script so that it allows DOM manipulation
try {
$("container_c2a3b6f3c3fa9e90d8a538ca050131c8").hide();
} catch(error) {}
// Replace "c2a3b6f3c3fa9e90d8a538ca050131c8" with the sys_id of your Container Start variable.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 03:25 AM
It was solved!
A container start + end was needed. I missed the container end variable! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 08:08 PM
Glad to know.
Share the detailed steps and script so that it helps other members as well.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader