Issue with dot walking on a UI policy/Client Script

germc
Giga Expert

Details: Hi guys,
I have a UI policy set up and it is designed to hide a field on the incident form under the 'Closure Information' section at the bottom.
For some reason it does not work. I am dot walking to the 'parent' field within the 'Resolution Profile'. I have tested with all the fields in there and none work. However, if I change the condition to just 'Resolution Profile is any of the profiles' it works and makes the field visible. I have contacted ServiceNow and they say there is an issue with this on Eureka.

So I was wondering if there was a way to get around this by using a client script.

Ive tried to dot walk by using the onchange script below but I cant get it to work.

Ive set the field name to 'Resolution Profile'.

So essentially we want the 'Source' field to be visible and mandatory only when the parent field on the resolution profile is set to 'Actioned (with Incident)'

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue == '') {

          return;

    }

var prof = g_form.getReference('u_resolution_profile');

if (prof.u_parent == 'Actioned (with Incident)')

          g_form.setVisible("u_source", true);

g_form.setMandatory("u_source", true);

}

1 ACCEPTED SOLUTION

Thanks guys,


That sent me in the right direction.


Ive now got it fixed,


The below script works for onchange.


If ye need it to work for onload then another will need to be created as onload but for now the below does exactly what we need.


Thanks again



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
          return;
    }
var prof = g_form.getReference('u_resolution_profile');

if (prof.u_parent == 'eed0fd44a5780a405b2538fa703d4a79') {
 
        g_form.setMandatory("u_source", true);
  g_form.setDisplay('u_source', true);
  g_form.setMandatory("u_root_cause", true);
    g_form.setDisplay('u_root_cause', true);


} else {
  g_form.setMandatory("u_source", false);
  g_form.setDisplay('u_source', false);
  g_form.setMandatory("u_root_cause", false);
  g_form.setDisplay('u_root_cause', false);
}
}


View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

HI Gerard,



Can you please have the alert statement and check what value you are getting. I am assuming it is not going in the if loop.


var prof = g_form.getReference('u_resolution_profile');


alert(prof.u_parent);


bernyalvarado
Mega Sage

Hi Gerard,



What type of record is your parent field?



Thanks,


Berny


bernyalvarado
Mega Sage

Also, I will recommend you use g_form.setDisplay('field_name', false) instead of... g_form.setVisible



I hope this is helpful.



Thanks,


Berny


surendarm
Kilo Expert

Hi Gerard,



To troubleshoot this issue,



1) check whether you have chosen the right field name in this onChange client script, before defining the code


2) Put alert('into the function'); statement after the first 'if' condition to verify if the script is executed or not


3) The way you have used the getReference is correct. To verify that, try giving   alert('Value'+ g_form.getReference('u_resolution_profile').u_parent);. This statement is equivalent to


var prof = g_form.getReference('u_resolution_profile');


var parent   = prof.u_parent;


4) Based on the above alert statments, you can check for kind of value you get and based on that you can modify the if condition.



Please update your findings and let me know if you have any questions