
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 02:48 PM
Hello fellow devs!
Any guidelines how to narrow down and filter the insertOrUpdate() ?
My point is - if I query the incident table , with a filter , only the first filter(field) is taken into account. Example:
var user = new GlideQuery('incident').insertOrUpdate({'short_description':'blah', state : 1, 'description': '222'}).orElse(null);
So, the second field is not taken into account as a filer for the query. Any clue how can I do that ?
Thanks!
Joro
Solved! Go to Solution.
- 1,501 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 05:03 PM
Oh and to answer your question, you need to resort to a "classic" update, if you want to filter by something else then sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 04:25 PM
Hi, perhaps a syntax issue as state is not encapsulated in 'quotes' so would not be seen as a field name.
Can you explain your business requirement\use case?
I would be extremely reluctant to deploy any insert\update functionality like this in any table based on 'text' fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 05:07 PM
The parameter is a JavaScript object. Whether the properties are written with or without single quotes or double quotes has absolutely no consequence. It only matters in a JSON string (that keys and string values are enclosed specifically in double-quotes).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 05:01 PM
Actually that is not how it works. If any of the changes is for a primary key field (basically sys_id) than it will do an update. If not sys_id is present, it will do an insert. This is what the comments for the method claim:
* Updates an existing record (just like update), however instead of requiring
* where calls, it uses the primary key(s) in the recordValues object passed
* in. If the primary key(s) isn't there, insertOrUpdate will insert a new
* record instead.
Internally what it does is to generate a "pure" insert or update GlideQuery plan and execute it. If sys_id is in the recordValues object, it generates an update plan (turns the sys_id recordValue into a where clause) and executes that, otherwise it generates an insert plan and executes that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 05:03 PM
Oh and to answer your question, you need to resort to a "classic" update, if you want to filter by something else then sys_id.