Selecting an option from a choice field on a Parent form sets a field visible on a child form

Jeff Wentworth
ServiceNow Employee
ServiceNow Employee

I am attempting to show a checkbox field on a child form based off of a selection made via a choice field on a parent form.

  • This is a new configuration to me.
  • I'm sure that setting a value on a parent form will make a field visible on a child form.
  • I have attached two screenshots to hopefully provide clarity of my ask.

Thanks in advance for any direction provided in this post.

7 REPLIES 7

Thanks Max!

 

I will begin configuring a new BR and update this POST/Feed w/my results.

Manmohan K
Tera Sage

Hi @Jeff Wentworth 

 

You need to write a on load client script on the child form.

 

In the client script, you need to make a GlideAjax call to a script include. This script include will have code that will check if Facial hair color selected is grey or not on parent record and return true or false accordingly.

Now you can check response in your client script and based on the response received, hide or show the checkbox

 

Sample client script code

function onLoad() {

   var parentSysId = g_form.getValue('parent'); // Get the sys_id of the parent record

   var ga = new GlideAjax('MyScriptInclude'); // Replace 'MyScriptInclude' with the actual name of your Script Include

   ga.addParam('sysparm_name', 'checkChoice');

   ga.addParam('sysparm_parent_sys_id', parentSysId);

   ga.getXML(onComplete);
}

function onComplete(response) {

   var answer = response.responseXML.documentElement.getAttribute('answer');

   if (answer === 'true') {

      // Show the checkbox if the choice is "Grey"
      g_form.setDisplay('show_section_five', true );

   } else {

      // Hide the checkbox 
      g_form.setDisplay('show_section_five', false );
   }
}

 

Sample Script Include

 

var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   checkChoice: function() {
      var parentSysId = this.getParameter('sysparm_parent_sys_id');
      
      var recordGR = new GlideRecord('table_name');
      if (recordGR.get(parentSysId)) {
         var choice = recordGR.getValue('facial_hair_color');
         
         // Check if the choice is "Grey"
         var isGrey = (choice === 'grey');
         
         return isGrey.toString();
      }
      
      return 'false'; // Return false if Facial hair color is not "Grey"
   },

   type: 'MyScriptInclude'
});

 

 

Thank you so much, Manmohan K.

 

Between you, Tony, and Max, I should have enough to produce a successful solution.

 

As I mentioned above, I will update this POST/Feed once I have developed and successfully test that solution. 🙂