Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Is there an easy way to determine the field type of a GlideElement?

akaupisch
Kilo Guru

In my server side code, I want to determine if a field is typeof phone number, then do formatting on it. The best I've come up with is:

gr.getElement('phone').getED().internalType =='ph_phone'

but this seems really kludgy. Is there any exposed API that will do what I'm looking for? so far I haven't found any...

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

That's the way I know it as well and that' show it's documented as well:

 

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideElement_global/concept/c_GlideElementAPI.html#ariaid-title19

 

See example in the documentation:

 

var fields = current.getFields();
for (i=0; i<fields.size(); i++) { 
  var field = fields.get(i);
  var descriptor = field.getED(); 
  gs.print("type=" + descriptor.getType() + 
    " internalType=" + descriptor.getInternalType()); 
}

View solution in original post

2 REPLIES 2

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

That's the way I know it as well and that' show it's documented as well:

 

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideElement_global/concept/c_GlideElementAPI.html#ariaid-title19

 

See example in the documentation:

 

var fields = current.getFields();
for (i=0; i<fields.size(); i++) { 
  var field = fields.get(i);
  var descriptor = field.getED(); 
  gs.print("type=" + descriptor.getType() + 
    " internalType=" + descriptor.getInternalType()); 
}

Thanks, was hoping there'd be a better way. Kinda lame if you have to look it up each time what each field type translates to