difference between getTableName and class name

Amey3
Giga Expert

Hi 

I am looking  for  the difference between getTableName() and sys_class_name

any approach with practical implementation is appreciated.

Thanks in Advance

Amey

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Please reference this post which asks the same question: https://community.servicenow.com/community?id=community_question&sys_id=6a3e87eddb9cdbc01dcaf3231f96... and contains use cases, etc.

Essentially, once is utilizing a field on a table to retrieve that information whereas the other is calling a function...to then go and get it. So it's advisable to use the field versus calling a separate function to go and retrieve it if it exists (i.e. only exists on tables extended from Task).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

11 REPLIES 11

Hi,

Understood. I did more than just give the link though...I explained it as well, but I understand. Just know though that some posts on the community might not have the correct answer marked, but the information is still good. You can tell this by replies being marked as "Helpful", etc. Also, in the future, if you're thinking of a thread or have referenced a thread before making your post, be sure to include that in your post so that we don't waste time by mentioning stuff you "already knew". We'd love to see that you've referenced 'x,y,z' post so that way we can cover new information for you 🙂

Either way, thank you for helping the community by marking posts as Correct so that it does help others when they search.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Gaurav Shirsat
Mega Sage

Hi Amey

 if you query any table and use getTableName() will give you the  cmdb_ci which is servicenow database management because that is the table you queried

and sys_class_name will give you the actual record's table name.

That Means you will get the table name when you use getTableName().

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat

Thanks.

Actually I am looking in little detail.

 

Siddhnath Pande
Mega Guru

Hi

If you were to query the cmdb_ci table for and print g_form.getTableName and sys_class_name for all records, g_form.getTableName is client side and that would return cmdb_ci because that is the table you queried, whereas current.sys_class_name is an server side that  would return the actual record's table name if it should happen to be a child table such as application, database, etc.

sys_class_name is the system field present on the table which basically gives the table name. For example

var gr = new GlideRecord('incident');

gr.get('c8ea74c72f012010ce8952492799b641'); //add any of you incident records sys_id

gs.addInfoMessage(gr.sys_class_name); //You can see a Message “incident”

 getTableName:- It is GlideRecord Method that will return you the associated Table Name.

to be concluded:- getTableName() is client side and current.sys_class_name is server side.

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server_legacy/c_GlideRecordAPI

If the above code helps then please mark my answer Correct and Helpful.

Thanks and Regards:
Siddhnath Pandey

Hi,

I'm sorry. This is not entirely true.

You'd wouldn't query client side anyway as that is not best practice and getTableName() is available server side as well and actually has to be used if you need to get the table name for any table that is not extended from Task as those tables don't include a field called: sys_class_name. Basically, it's not limited to only being used in client side operations as you've stated.

So it can help you in client side to figure out the table name, yes, but it's not limited to client only.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!