- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:02 AM
Hello everyone,
Im still new to Servicenow and have an issue with a Business rule not updating on insert
with the following script attached
So this script works on Update but not on Insert . Through my testing it seems that on insert the record fields are blank so this is nothing to put into the field. Does anyone know how I
would work around this?
Thanks for everything in advance guys and gals
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:09 AM
Hi Andrew,
Sys ids are generated after insertion. You can simplify your code. You dont need sys_id. Try the below code and it should work.
(function executeRule(current, previous /*null when async*/) {
if (current.sys_class_name == 'incident')
{
current.u_requester = current.caller;
}
else if (current.sys_class_name == 'sc_req_item')
{
current.u_requester = current.request.requested_for;
}
else if (current.sys_class_name == 'sc_task')
{
current.u_requester = current.request_item.request.requested_for;
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:09 AM
Hi Andrew,
Sys ids are generated after insertion. You can simplify your code. You dont need sys_id. Try the below code and it should work.
(function executeRule(current, previous /*null when async*/) {
if (current.sys_class_name == 'incident')
{
current.u_requester = current.caller;
}
else if (current.sys_class_name == 'sc_req_item')
{
current.u_requester = current.request.requested_for;
}
else if (current.sys_class_name == 'sc_task')
{
current.u_requester = current.request_item.request.requested_for;
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:14 AM
THANKS!!!! YOU DA BEST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:12 AM
update the when condition to "after",i think your problem will solve.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2017 10:14 AM
Hello Andrew,
Try to use after insert business rule, since before inserting you won't be having a sys_id which might result in unexpected result.