update() function not actually updating record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 02:03 PM
I have a script to copy data from certain fields on CI records, and then clear the 'source' fields. I had the script working a few months ago, but it 'got lost' during a clone/upgrade process. Now, I am trying to recreate it, without success.
The problem is the update() function is not actually updating the record.
According to the SN Docs site, Update() will return the sys_id of the record on a successful update. And I do get the sys_id back from the update() call.
However, if I then display the record's sys_updated_on (last Updated) field, it has not changed. It still shows the pre-update date and time. And the field data updates made by the script are not there.
This is happening on two different instances, so I don't believe it's something unique to an instance. More likely, it's something in my script. But my fellow admins and I an't find anything wrong.
Ideas as to what to look for? I'm attaching the complete script for your reference.
Thanks,
Dave
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 02:30 PM
Hi David,
A quick question. You have tested with the logs that it will go through and change something. I see you remove the while, so it's basically just going through 1 record here.
Result you get is pointing at no field values has been changed. If there is a field value you know should have changed, put a gs.info() or gs.debug()(if you use scripts background) to log that variable just before update.
example if you know assigned_to should have changed. do
gs.info("My field: " + ciRec.getValue('assigned_to'));
RC = ciRec.update();
and for a habit, I always use the setValue()/setDisplayValue() to be sure to avoid any weird things, something just using = mess stuff up, can't recall exactly what right now thou.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 02:36 PM
Goran,
Some good suggestions. I know that sys_updated_on did not change, and I thought it should have. But then, for those record, maybe there was no data to begin with.
Let me try a few things...
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 02:47 PM
well, if there isn't any other field that is changed, "sys_updated_on" doesn't change either.. like pressing save on a form that you haven't changed anything on.
if you still want to update the "sys_updated_on" you need to use setForceUpdate(true) to get it to "update". like ciRec.setForceUpdate(true), but I see no reason here to do so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 02:54 PM
Hi Goran,
I wasn't previously aware of setForceUpdate(true). The reason I would do a setForceUpdate(true) is so that my loop doesn't process the same 20, or 200, or 500 records over and over again. And that's what it's doing now. Processing the same 20(0) records over and over again, because the sys_updated_on hasn't changed.
I have 50k records to update. So, rather than update all 50K in one pass, I 'break' them into 'batches' of 500, and process 500 every 5 minutes. Looking at sys_updated_on as part of the encoded Query (Last Updated On BEFORE Today) will keep today's updates from being 'reprocessed'.
Dave