- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 10:06 AM
Hi There!
I need to create Incident based on Requested Item, using Business Rule, something like this:
var gr = new GlideRecord('incident');
gr.initialize();
gr.assignment_group = current.assignment_group;
gr.insert();
current.u_has_incident = true;
I have a problem with field "Has incident", which is not a form field. Without current.update() at the end, it will not be changed. On the other hand I saw few articles with advice not to use current.update() in Business rules... what should I do then to make it work?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 09:35 PM
Use an after business rule to create the incident as following
var gr = new GlideRecord('incident');
gr.initialize();
gr.assignment_group = current.assignment_group;
// add your fields that has to be ampped
gr.insert();
current.u_has_incident = true;
current.update();
current.setWorkflow(false);
The last will prevent any business rule or workflow condition to execute.
Please like or mark correct based on the impact of the response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 10:09 AM
HI Jakub,
Which business rule you are using.
Thank you,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 02:15 PM
Hi Jakub,
If you need to set a field on the current record the business rule is running against you'll need to run the business rule as a before insert/update.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 02:32 PM
After business rules should be used when creating/updating external records.
You do then run into the problem where if you want to update a field on current only after a new record is created, you have to do a current.update().
You should never put a current.update() in a 'before' Business Rule, but I think there are some circumstances when it is ok to do so in an after rule.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 02:32 PM
you shouldn't use update in a business rule unless the record has already been saved (after). If this is a before rule, and action is insert, just set the value of the record going in and your value will be saved. You especially don't want to use update in a before update, for obvious reasons.