Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Get the field information for customer_contact form

sahilkhanna
Tera Expert

I have retrieved the fields of the Contacts form (customer_contact) using the REST API. Below is the request and response below.

 

Request

{{instanceUrl}}/api/now/table/sys_ui_element?sysparm_query=sys_ui_section.view.name=ess&sys_ui_section.name=customer_contact&sysparm_fields=element


Response

{"result":[{"element":"preferred_language"},{"element":"email"},{"element":".begin_split"},{"element":"first_name"},{"element":"time_zone"},{"element":"phone"},{"element":"user_name"},{"element":"last_name"},{"element":".split"},{"element":"mobile_phone"},{"element":".end_split"},{"element":"title"},{"element":"account"},{"element":"notification"}]}

The response has 10 elements (excluding 4 split sections)

 

 

I want to get the attributes of these elements. Below is the API request and response.

 

Request

{{instanceUrl}}/api/now/table/sys_dictionary?sysparm_query=name=customer_contact&sysparm_fields=element,column_label

 

Response

{"result":[{"column_label":"Sys ID","element":"sys_id"},{"column_label":"","element":""},{"column_label":"Account","element":"account"}]}

 

I can get only 3 out of 10 elements, and only 1 of the 3 belongs to the result returned in the "sys_ui_element" response, i.e. "account".

 

How can I get all the customer_contact fields in "sys_dictionary" response? Or is there any other API/table I need to get this information from?

 

1 ACCEPTED SOLUTION

No worries @sahilkhanna., glad I can help.

 

To answer your followup questions specifically.

There is an field/column against a table labelled 'Extends table' (Database name: 'super_class') which if populated indicates which table the current table is extended from.

 

Another pointer, specifically related with CSM (Customer Service Management) and other scoped applications, this is known as a scoped app and there is an available direct API's available for this table 'sn_customerservice'.

 

API endpoint: {instanceURL}/api/sn_customerservice/case

 

Re the mandatory fields on extended table. In ServiceNow threes a concept known as a 'Dictionary override' whereby for columns/fields which are inherited, you can override and control the behavior at the required table level. As you've described, it is possible to make fields mandatory on a child level which may not or are not mandatory on a parent level.

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

 

View solution in original post

9 REPLIES 9

@Robbie. I understood what you said. I can now search for the missing fields in the "sys_user" table. Thank you.

 

{{instanceUrl}}/api/now/table/sys_dictionary?sysparm_query=name=sys_user^element=last_name&sysparm_fields=column_label,column_name,internal_type,mandatory,reference,max_length,attributes,choice,reference_key,use_reference_qualifier,default_value

 

I have two questions on this.

  • Is there a way I can find (programmatically using the REST API) if "customer_contact" is extended/inherited from "sys_user"? I also plan to use other tables, e.g. "cn_customerservice_case", "sn_customerservice_entitlement", etc., that may extend some other tables.
  • In the Contact (customer_contact) screen, I can see that "Last Name" and "Email" are mandatory fields, however, these fields are not mandatory in "sys_user". How do I deal with this? Am I invoking the API correctly?

No worries @sahilkhanna., glad I can help.

 

To answer your followup questions specifically.

There is an field/column against a table labelled 'Extends table' (Database name: 'super_class') which if populated indicates which table the current table is extended from.

 

Another pointer, specifically related with CSM (Customer Service Management) and other scoped applications, this is known as a scoped app and there is an available direct API's available for this table 'sn_customerservice'.

 

API endpoint: {instanceURL}/api/sn_customerservice/case

 

Re the mandatory fields on extended table. In ServiceNow threes a concept known as a 'Dictionary override' whereby for columns/fields which are inherited, you can override and control the behavior at the required table level. As you've described, it is possible to make fields mandatory on a child level which may not or are not mandatory on a parent level.

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

 

@Robbie, thank you for explaining it in detail. I can retrieve the missing fields as below.

 

  • The "super_class" of the object should be traversed upwards until the "super_class" of the root object is empty.
  • Search for the field attributes in all the "super_class" in the object parent tree.

I made use of the below APIs.

{{instanceUrl}}/api/now/table/sys_db_object?sysparm_query=name=customer_contact&sysparm_fields=super_class

{{instanceUrl}}/api/now/table/sys_db_object/{{super_class_id}}?sysparm_fields=name,label

 

I understand that the child object (contact in our case) can mark an inherited field (email) as mandatory. While I'm able to get this field from "sys_user", I'm not sure if I can know if it is mandatory for "customer_contact" (while it is optional for "sys_user"). Is there a way I can get this from the REST API?

Hi @sahilkhanna,

 

Glad I can help. Re how we can determine whether a field is mandatory via dictionary override via an API - hmmmm, let me think about that. I do love a brain teaser.

 

Whilst I think about that, can I please ask, so as to help others in the community and for me to gain recognition for my efforts, please can you Accept as Solution and/or Kudos for the original question.

 

Thanks, Robbie

@Robbie, I have accepted your answer. Please see if you can guide me on " how we can determine whether a field is mandatory via dictionary override via an API -😊