- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 01:07 AM
My usual approach when working with GlideRecord is to assign values using gr.setValue(<fieldname>, <string>). However, I've noticed that many other developers prefer direct assignment, like gr.fieldname = <string>.
Today, I tried to set the task.comments field using setValue() and realized that Journal Input fields only work with direct assignment — the comment simply didn’t go through otherwise.
That got me thinking:
How do you typically assign values to fields in Business Rules or Script Includes?
Do you stick with setValue(), or do you prefer direct assignments depending on the field type?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:29 AM
Hi,
Using setValue is better.
Embarassed to say how often I have used gr.fieldname = <string> myself 😞
Do as i say, not as I do 😛
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:37 AM
Hi,
Great question!
I usually use setValue() for most fields, especially in generic scripts where the field name might be dynamic. But when it comes to Journal fields like comments or work_notes, I always use direct assignment (gr.comments = 'text') — like you noticed, setValue() doesn't work for them.
So for me, it depends on the field type:
Regular fields → setValue() or direct assignment (both work)
Journal fields → always use direct assignment
If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.
Best,
Tairone Alb.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:23 AM
The recommended approach is to use 'getters and setters' so setValue and getValue to avoid GlideRecord issues when using direct assignment, like sys_ids and other objects to an array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:29 AM
Hi,
Using setValue is better.
Embarassed to say how often I have used gr.fieldname = <string> myself 😞
Do as i say, not as I do 😛
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:37 AM
Hi,
Great question!
I usually use setValue() for most fields, especially in generic scripts where the field name might be dynamic. But when it comes to Journal fields like comments or work_notes, I always use direct assignment (gr.comments = 'text') — like you noticed, setValue() doesn't work for them.
So for me, it depends on the field type:
Regular fields → setValue() or direct assignment (both work)
Journal fields → always use direct assignment
If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.
Best,
Tairone Alb.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 12:23 AM
Thanks so much to everyone who replied!
Your input really helped me understand whether I’m on the right track – and that’s exactly what I was hoping for.
Appreciate this awesome community!
– tooManyTabs