The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Client Script not working on Service Portal

Zod
Giga Guru

Hi Experts,

I understood, that normal client scripts will not work on service portal ... I also found some posts regarding this issue, but I don't get it. How to achieve ... you anyone please tell me in more detail what to do?

My on client scripts is something like this ...

function onLoad() {

  if (g_form.getUniqueValue() !== g_user.userID)

  {

  g_form.removeOption('u_abc', 1);

  g_form.removeOption('u_def', 1);

}

  }

21 REPLIES 21

Still not working.



Alter shows nothing if field empty and the date in case field filled - so this should be ok, just the g_form.setDisplay('u_xxx', false) does not work for empty.



For bolean fields it does not show anythin via the altert - neither with or without .toString()


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vem



It doesn't sound good.


I tried on my instance your code with a true/false field on the asset table


It works fine.



Have a look.



a.png



b.png



c.png



d.png



Are you sure you have that field (u_xxx) on the form ?


What's the type of that field (u_xxx) ?


Are you sure there isn't another client script messing around with that field ?


Did you check if the field is mandatory ?



Cheers


R0b0


Are you sure you have that field (u_xxx) on the form ?                                                                              


>>> yes


What's the type of that field (u_xxx) ?                                                                                                                                          


>>> date


Are you sure there isn't another client script messing around with that field ?    


>>> if so, it would not force any other action - BUT I have ui-policies that do the same as the client script, just they do not work either ... if I disable the Clients Script, the ui_policies do NOT apply ...


Did you check if the field is mandatory ?


>>> no is not mandatory (but read only)


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vem



It wasn't clear it was a date.


Try this one than



function onLoad() {


  alert('u_xxx is ' + g_form.getValue('u_xxx'));


  if (g_form.getValue('u_xxx').toString() === '')       {                       /


          g_form.setDisplay('u_xxx', false);                           // Hide


  }


}



For a date that syntax doesn't make sense. It won't work.


On the other hand if you can convert the date to a string and the string is empty the code between the if should be finally triggered.



ps i tested on my instance first..it should work on the portal as well



Cheers


R0b0


Brian Lancaster
Tera Sage

I have noticed that g_user is not listed in the support and unsupported scripts at all.   Supported and unsupported client scripts