How do I use gr.setValue();?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2023 06:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 03:54 AM
Hi @Anshul Duvey ,
Please refer the below link.
Mark my answer as accepted solution and helpful if helps you.
Thanks,
Nivedita Patil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2023 05:00 AM
// Assuming 'incident' is the table name
var gr = new GlideRecord('incident');
// Query for a specific record (you might want to add more conditions based on your use case)
gr.addQuery('number', 'INC001234');
gr.query();
// Check if the record was found
if (gr.next()) {
// Set the value of the 'short_description' field to 'Updated Short Description'
gr.setValue('short_description', 'Updated Short Description');
// Save the changes to the record
gr.update();
} else {
gs.info('Record not found');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2023 10:29 AM
whats the difference between
gr.setValue('short_description','Test short description');
//and
gr.short_description = 'Test short description';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2025 02:38 AM
you probably found your answer by now, but if it can be useful for anyone.
Normally a script would do a direct assignment, for example now_GR.category = value. However, if in a script the element name is a variable, then you can use now_GR.setValue(elementName, value). When setting a value, ensure that the data type of the field matches the data type of the value you enter.
If the value parameter is null, the record isn't updated, and an error isn't thrown.