current.update() on "Insert" only Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2019 07:59 AM
I am writing a business rule to inherit a custom field value on change_task from change_request, however when the business rule runs on update, change_task records that are created at the creation of the change_request record by a workflow running on change_request are seen as null by the before business rule.
If the business rule is run after or async, however, the values on the parent change_request record are what they were submitted as (not null).
I know that current.update() in a business rule is a big no-no - I have felt the wrath of the consequences of such a business rule - but what about if a business rule only runs on insert? Then using current.update() shouldn't be an issue, right? This is my only working solution at this point, and it seems like this should be a pretty simple function, but it hasn't proven to be in practice. Any help is appreciated!
I floated the question here, but it didn't seem to get too much traction: https://community.servicenow.com/community?id=community_question&sys_id=e18772fcdb231344a39a0b55ca96...
Thanks!
Scott
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2019 10:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2019 11:56 AM
Hi Scott, have you tried to set your before business rule with an order of more than 1000. These business rules will be run after the workflows but before the insert.
I think this might be the solution you are looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2019 12:09 PM
Unfortunately that didn't work either. Good thought!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2019 12:23 PM
Therefore, your change tasks must be inserted after the insertion of the change request. What does the workflow creating the change task looks like, is it the workflow that inserts the change to allow the change tasks to refer to the change request?
If the insertion of the change request is done in workflow to allow having the sys_id for the reference, then you might consider creating the tasks before you insert the change request. You can get the sys_id of your change request before the insertion by using current.setNewGuid(), then you can retrieve the sys_id with current.sys_id.
If this is not possible, you have no choice to update the change following it's insertion, then you could run your script inside your workflow or on business rule running after insert of the change task but the result will be the same, you will run an update on a record that had just been inserted.