Fetch field in the client script which is not available in the form

Nikita35
Kilo Guru

hi

I have one field which is not visible on incident form but it is there.

based on that field I need to set another field mandatory in my client script.

I am guessing I cannot fetch field value using g_form as its not available on the form.

Do I need to do Display business rule and call g_scratchpad variable at client script?

Any suggestions on this please?

4 REPLIES 4

Stephen Sturde
Tera Guru

Hi Nikita -

You have a few options here. 

  1. Place the field on your form and hide it with UI policy or g_form.setDisplay('fieldName', false) in onLoad client script. This method allows you to use g_form.getValue
  2. Create a script include to pull the value, and call the script include within your client script using GlideAjax
  3. You can do as you described, use a display business rule doing the g_scratchpad method to get the value to your client script
-Stephen

SatheeshKumar
Kilo Sage

Make use of display business and g_scratchpad to handle this situation.

 

check the below link for an example of display business rule 

-satheesh

Sumanth16
Kilo Patron

Hi,

 

I am not 100% sure but please try using getReference function in script.

 

Please refer below link:

https://community.servicenow.com/community?id=community_question&sys_id=9a0dc769db9cdbc01dcaf3231f96...

 

Thanks,

Sumanth

Soumita3
Tera Expert

Hi Nikita,

 

To achieve the above scenario, the following scripts needs to be written.

At first a Display business rule to store the value of the field not available on the form:

g_scratchpad.group_name= gs.getUser().isMemberOf('Testing group');   // for example taking up the member of the testing group here

 

Next we need to write the Client script: (making the fields visible or mandatory)

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Type appropriate comment here, and begin script below
if(g_scratchpad.group_name)
{
if(newValue == '3')
{
alert('hi');
g_form.setVisible('u_test_field', true);
g_form.setMandatory('u_test_field', true);
}
}
}

 

Please mark the answer as correct if it suffice your query.

 

Thanks

Soumita.