Dot walk VS .setValue()

bonsai
Mega Sage

I'm wondering which of the two methods below I should use to update a field.

I think they have the same effect, but which one is recommended?

I don't fully understand the specifications of dot walk, but if it is implicitly converted to "setValue", I thought that using "setValue" would put less strain on the system.

 

 

 

current.u_field_1 ="test";
current.update();

 

 

 

2

 

 

current.setValue("u_field_1","test");
current.update();

 

 

 

3 ACCEPTED SOLUTIONS

Simon Christens
Kilo Sage

Hi,

In general theres not much difference between setting a field either way.

My personal experience though says that its more consistent to use .setValue() than using .field = something because not all fields are strings and you can risk that the field is not set if theres a mismatch between for field type and input type.

With that in mind when updating comments and work_notes setValue doesnt work so in those cases .comments or .work_notes needs to be populated with "dot-walk".

https://www.servicenow.com/community/developer-forum/how-to-populate-additional-comments-with-value-... 

 

Hope it clarifies a bit 🙂

View solution in original post

Jim Coyne
Kilo Patron

Just wanted to clear something up here: dot-walking is about referencing a different record via Reference fields and not just the field itself.  So...

user.location.country.getValue();

...is an example of getting the Country information from the "location" record tied to the "user" record via the Reference field using the dot-walking method.  The "country" part is on the "location" record and not the "user" record.  Here you are dot-walking (accessing) to the location record and then accessing the Country field on a completely different record.

 

Getting or setting the value of the user.location field is not an example of dot-walking.  "location" is just a property on the "user" record object.  You reference the field or property using the "record_name.field_name" format.

View solution in original post

5 REPLIES 5

Community Alums
Not applicable

KrishnaMohan
Giga Sage

Hi @bonsai ,

 

Purposes of Dot Walking and setValue or getValue methods is to set or get values. However as per ServiceNow docs it is recommended do not use dot walking in same cases. Due to database operations dot Walking can lead to performance issues.

KrishnaMohan_0-1724299155461.png

 

Please find the ServiceNow best practices link here

https://developer.servicenow.com/dev.do#!/guides/washingtondc/now-platform/tpb-guide/scripting_techn...

 

If my answer helped you, kindly mark it as correct and helpful.

 

Regards,

Krishnamohan

Simon Christens
Kilo Sage

Hi,

In general theres not much difference between setting a field either way.

My personal experience though says that its more consistent to use .setValue() than using .field = something because not all fields are strings and you can risk that the field is not set if theres a mismatch between for field type and input type.

With that in mind when updating comments and work_notes setValue doesnt work so in those cases .comments or .work_notes needs to be populated with "dot-walk".

https://www.servicenow.com/community/developer-forum/how-to-populate-additional-comments-with-value-... 

 

Hope it clarifies a bit 🙂

Jim Coyne
Kilo Patron

Just wanted to clear something up here: dot-walking is about referencing a different record via Reference fields and not just the field itself.  So...

user.location.country.getValue();

...is an example of getting the Country information from the "location" record tied to the "user" record via the Reference field using the dot-walking method.  The "country" part is on the "location" record and not the "user" record.  Here you are dot-walking (accessing) to the location record and then accessing the Country field on a completely different record.

 

Getting or setting the value of the user.location field is not an example of dot-walking.  "location" is just a property on the "user" record object.  You reference the field or property using the "record_name.field_name" format.