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

Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vem



Let me try to help you. Quick question.


Could you please show me with a snapshot the widget that should be affected by the code ?



Cheers


R0b0


Just checked with him. Can not influence.


But he said, that to his knowledge only catalog client scripts do work on SP not "normal" client scripts ... true?!


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vem



Client scripts created on the back end (onChange, onLoad etc) work in service portal if you use the 'form' widget.  


In that case the system renders the original form in the portal executing any script available.


On the other hand if you use a different widget that is not replicating the original form the code won't be execute.


Plus i don't think you can use the usual methods inside of a 'client controller'.



For instance on this widget the script we were discussing won't affect any of the fields.



Customer_Service_Portal_-_User_Profile.png




Cheers


R0b0


So ... we use the FORM Widget ... but my client script does not seem to work ...



function onLoad() {


  if (g_form.getValue('u_xxx') !== 'true')       {         // if not true


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



  }



UI Type is "ALL"



THANK YOU !!!


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Vem



Could you please try to put a couple of alert




function onLoad() {


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


  if (g_form.getValue('u_xxx') !== 'true')       {         // if not true


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


  }


}



Other small thing. If your field is a boolean i would suggest to cast it as String.


g_form.getValue('u_xxx').toString() !== 'true'


because your syntax !== check the content and the type as well is not just !=



Cheers


R0b0