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.

getNullValue does't work although I can update the parent field via gr.setValue('parent', sysID)

Lisa71
Tera Contributor

I can use gr.setValue('parent', targetSysId); to update the parent field of a kb article to a specific KB, however, I can't use gr.setNullValue('parent'); to set the parent field to NULL, why?

1 ACCEPTED SOLUTION

Nawal Singh
Tera Guru

Hi @Lisa71 ,

The parent field is a reference field, and setNullValue() does NOT work on reference fields

 

ServiceNow is inconsistent here:

setNullValue() only reliably works on certain field types (string, numeric, date, etc.).

For reference fields, the platform may ignore setNullValue().

 

This is a known platform quirk — reference fields often need to be nulled using setValue() instead

 

gr.setValue('parent', '');

OR

gr.parent = '';

 

View solution in original post

4 REPLIES 4

Nawal Singh
Tera Guru

Hi @Lisa71 ,

The parent field is a reference field, and setNullValue() does NOT work on reference fields

 

ServiceNow is inconsistent here:

setNullValue() only reliably works on certain field types (string, numeric, date, etc.).

For reference fields, the platform may ignore setNullValue().

 

This is a known platform quirk — reference fields often need to be nulled using setValue() instead

 

gr.setValue('parent', '');

OR

gr.parent = '';

 

Thank you! This helps!

Juhi Poddar
Kilo Patron
Kilo Patron

Hi @Lisa71 

 

To meet the requirement, please try the following script:

gr.setValue("parent", "");

OR

gr.setValue("parent", "NULL");

ServiceNow does not provide an out-of-the-box setNullValue() method on GlideRecord, so using an "NULL" or an empty string with setValue() is the correct approach to clear the field.

 

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Laveena-Agarwal
Kilo Sage

Hi @Lisa71 

 

As @Juhi Poddar  , there is no method under GlideRecord as "setNullValue". I also looked into API documentation multiple times, couldn't find one.

You can follow this ServiceNow documentation  to set the Null - https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/script/server-scripting/reference/r...