GlideQuery - how to update records with Stream methods?

NS
Kilo Sage

Hello,

 

I've been wondering for a while how to update records using GlideQuery while interacting with the records with methods like filter(), map() or forEach(). The documentation mentions this being possible: "For example, you can use the forEach() method to update the state of each record in a stream returned by the GlideQuery API." (link to developer reference).

However neither the SN Docs, developer reference or the SN Developer Blog posts show any examples how to achieve this? With no idea how to do this, I fail to see how the GlideQuery is all that useful since it forces me always to return to GlideRecord.

 

Here's a nonsensical example but it touches the issue:

// Let's pretend I need to adjust the 'last_login' field for all users by +1 month.
var gq = new global.GlideQuery('sys_user')
    .where('user', 'IN', [user_sys_ids])
    .where('status', '=', 'active')
    .select('last_login')
    .map(function (date){
        var gdt = new GlideDateTime(date['last_login']);
        gdt.addMonths(1);
        return gdt.getDate();
    })
    // At this point how would I update the records in the Stream with the extended 'last_login' value?
1 ACCEPTED SOLUTION

NS
Kilo Sage

I received an explanation to my question straight from Peter Bell. Hope someone else might find it useful as well.

 

"We’ve seen this question before and have thought about adding a per-record update. Currently there isn’t a special way to do this, so you would need to do something like:"

(I attached the code sample as an image since the forums threw an error when I tried to insert it to text, code block or directly to HTML)

View solution in original post

1 REPLY 1

NS
Kilo Sage

I received an explanation to my question straight from Peter Bell. Hope someone else might find it useful as well.

 

"We’ve seen this question before and have thought about adding a per-record update. Currently there isn’t a special way to do this, so you would need to do something like:"

(I attached the code sample as an image since the forums threw an error when I tried to insert it to text, code block or directly to HTML)