Field type determination

bonsai
Mega Sage

I would like to perform processing only on fields of type "Date/Time". (server side script)

I am thinking of storing all fields in an array and processing them, and only making judgments and processing in the case of date/time fields.

Is there a way to get the field type?

1 ACCEPTED SOLUTION

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
You can get the type in server-side code referring below script-

var grInc = new GlideRecord('incident');
grInc.query('priority', '1');
 
var field = grInc.getElement('sys_updated_on');
var ed = field.getED();
 
var isEdge = ed.getInternalType();
gs.info(isEdge);

Thanks and Regards,

Saurabh Gupta

View solution in original post

3 REPLIES 3

Prathamesh G
Kilo Sage
Kilo Sage

Hello @bonsai,

 

You can use the 'typeof()' method to determine the type of your specified field. Please refer to the below code snippet for the reference:

https://www.workingcode.in/question/typeof-operator-use-in-servicenow/

 

If the above answer resolve your issue, Please marked the answer as 'Accepted Solution' and also marked it as 'Helpful'.

 

Thank You!

Prathamesh.

Is it possible to know the type of the field ('internal_type' in the dictionary record) rather than the type of value to set in the field?

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
You can get the type in server-side code referring below script-

var grInc = new GlideRecord('incident');
grInc.query('priority', '1');
 
var field = grInc.getElement('sys_updated_on');
var ed = field.getED();
 
var isEdge = ed.getInternalType();
gs.info(isEdge);

Thanks and Regards,

Saurabh Gupta