We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

client script, variable, focus

scottl
Kilo Sage

In the Service Portal, how does one get a form element variable, of a catalog item, within a client script so one can set the focus on that input?  

22 REPLIES 22

CORRECTION - to fix the issue with the showFieldMsg, be sure to set the scroll form parameter to false




Method DetailParametersExample
showFieldMsg(input, message, type, [scrollform])
  • input - name of the field or control
  • message - message you would like to display
  • type - either 'info' or 'error', defaults to info if not supplied
  • scroll form - (optional) Set scrollForm to false to prevent scrolling to the field message offscreen.

Yep, that would do it ~



Cheers !


Adam Syed1
Kilo Contributor

To focus on a field in record producer on portal side copy and paste the below code in your onload client script and replace the "011a705e1355d348eb633598d144b023" with the sys_id of that field.

 

setTimeout("var refocus = document.getElementById('sp_formfield_IO:011a705e1355d348eb633598d144b023');refocus.focus();",0);

 

 

Thanks,

Adam Syed