How to run a same script on 2 tables ?

AbdulAzeez
Mega Guru

Hello Everyone,

I have a client script which i wanted to run on 2 tables like Incident & task table ?

How can i achieve this ?

1 ACCEPTED SOLUTION

Hi Abdul,



The Inherited functionality, alone, on a client script would be useful only if you would want that script to run all the extended tables of a base table.



However, since in your case, you want the script to run only on Incident and Catalog Task table, you can do the following:




1) Create the client script on the base table, i.e. TASK


2) Check the Inherited checkbox on the script


3) In the starting of the script, use the following condition to ensure that the script is running only on Incident and Catalog Task table and not on other inherited tables from the TASK table:


        function onLoad() {    


                  var table = g_form.getTableName();


                  if (table == 'incident' || table == 'sc_task')


                  {


                            //alert('Run my script');


                            //place your code here


                  }


}




This should work and will make this script run on only the Incident and the Catalog Task tables extended from Task. Let me know if it doesn't.



PS: Mark this answer as Correct if it solved your query or hit Like/Helpful depending upon the usefulness of the response.



Regards


Supriya Bisht


View solution in original post

18 REPLIES 18

Hi Abdul,



One question before I can answer more accurately, do you want to run this script on all the extended tables of the base TASK table?



Regards
Supriya Bisht


Not on all tables, only on 2 tables which were extended from Task.



I think if we want run the script on all extended tables we can write Client script on Global table under client scirpt table name right ?


6 Avoid Global Client Scripts

A global client script is any client script where the selected Table is Global. Global client scripts have no table restrictions, therefore they will load on every page in the system introducing browser load delay in the process. There is no benefit to loading this kind of scripts on every page.


As an alternative, and for a more modular and scalable approach, consider moving client scripts to a base table (such as Task[task] or Configuration Item[cmdb_ci]) that can be inherited for all the child/extending tables. This eliminates the system loading the scripts on every form in the UI - such as home pages or Service Catalog where they are rarely (if ever) needed.


I'm asking for some clarification from ServiceNow on this.  My testing would appear to show that the scripts only run on the normal form-based pages and NOT in list views, Dashboards, Homepages. etc...

Hi Abdul,



The Inherited functionality, alone, on a client script would be useful only if you would want that script to run all the extended tables of a base table.



However, since in your case, you want the script to run only on Incident and Catalog Task table, you can do the following:




1) Create the client script on the base table, i.e. TASK


2) Check the Inherited checkbox on the script


3) In the starting of the script, use the following condition to ensure that the script is running only on Incident and Catalog Task table and not on other inherited tables from the TASK table:


        function onLoad() {    


                  var table = g_form.getTableName();


                  if (table == 'incident' || table == 'sc_task')


                  {


                            //alert('Run my script');


                            //place your code here


                  }


}




This should work and will make this script run on only the Incident and the Catalog Task tables extended from Task. Let me know if it doesn't.



PS: Mark this answer as Correct if it solved your query or hit Like/Helpful depending upon the usefulness of the response.



Regards


Supriya Bisht