Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

TypeScript GlideRecord's Type Parameter

UIB Whisperer
Tera Expert

Hey there!

I've converted an existing application still in development to a NowSDK version of it and I've ran into a problem when it comes to declaring the type parameter of the GlideRecord class. I want to be able to dot-walk into the GlideElement objects of the GlideRecord one like in the example below which I've invented.

 

import {
	GlideAggregate,
	GlideDateTime,
	GlideRecord,
	GlideScopedEvaluator,
} from '@servicenow/glide'

export default class AccessRequestAPI {
	endpoint_gr: GlideRecord<HTTPMethod>
	rest_message_gr: GlideRecord<RESTMessage>
	constructor(endpoint_gr: GlideRecord<HTTPMethod>) {
		this.endpoint_gr = endpoint_gr;
		
		this.rest_message_gr = this.endpoint_gr.rest_message.getRefRecord(); // Returns String -> Error cause not a valid type
	}
}

 

 I know I can use the "any" type and TypeScript will hide the message when the transpiler is set to not strict but having it as strict is a best practice and I want to know if there's a way that I'm not seeing to achieve this.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Venkat79
ServiceNow Employee

Hi @UIB Whisperer,

We donot support dot-walking for table fields or other types in GlideRecord yet.

As of now, the sole purpose of the types in "@servicenow/glide" package is to provide intelli-sense in the IDE and to make modules aware of the Glide APIs available at runtime.

And types for "RestMessageV2" are available under the "sn_ws" namespace, which can be imported in modules using

import { RestMessageV2 } from "@servienow/glide/sn_ws"


Thanks

View solution in original post

7 REPLIES 7

Venkat79
ServiceNow Employee

Hi @UIB Whisperer,

We donot support dot-walking for table fields or other types in GlideRecord yet.

As of now, the sole purpose of the types in "@servicenow/glide" package is to provide intelli-sense in the IDE and to make modules aware of the Glide APIs available at runtime.

And types for "RestMessageV2" are available under the "sn_ws" namespace, which can be imported in modules using

import { RestMessageV2 } from "@servienow/glide/sn_ws"


Thanks

Hey @Venkat79, thank you for your response. I did figure out the module where those are exported but could not figure out the part on how to implement a typed GlideRecord. Is this last one going to be addressed? If so, anytimeline?

Hi @UIB Whisperer, Yes we will be adding support for Typed GlideRecord but I won't be able to provide a timeline. Sorry. 

- Venkat