Trigger script when the tab is clicked in a form

Aditya Prasad
Tera Contributor

Hello Everyone, 

 

I have added a new section(tab) in Incident form. This section has a ui macro which loads more information by making REST api calls on load event(ui macro onload javascript). 

The sections are loaded as soon as the incident form is loaded. 

My requirement is, I want to call these APIs only when user clicks on this section.

So is there any script which I can run when the tab becomes active?

 

Thanks

1 ACCEPTED SOLUTION

Pleasure! 

We had similar requirement long back and convinced customer to go with simpler alternative 🙂 

You can mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards

View solution in original post

7 REPLIES 7

mdash
Giga Guru

Hello Aditya,

As DOM manipulation is discouraged in client side, we have a couple of options to achieve this in a optimal way.

1) You can create a checkbox of some kind inside that tab(section), onChange define a client script which will call a script include and trigger REST message.
2) You can explore the tab2section methods. You can have a look and determine if any one of these methods can come handy in your case.
https://www.servicenow.com/community/developer-blog/demystifying-form-tabs/ba-p/2287086

You can mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards



Thanks for the response @mdash 

If we have a checkbox, how can we make sure it is checked on click of the tab ? 

I am afraid that has to be user initiated. OOTB onChange Client script does not support form section changes. 

You can also explore the option of adding an UI action (for ex: Refresh data) instead of checkbox to trigger the REST Call. 

Right, In that case may be I will have a button so that user can initiate.

Thanks for the all information. @mdash