- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2022 05:06 PM
We have a requirement that when the SCTASK requested for field changes the job location field gets populated base on the the requested for location. This does not work. Any ideas or any help will be much appreciated.
I have created a business rule on the sc_request table;
update is true
Filter conditions
Requested for changes
Script;
(function executeRule(current, previous /*null when async*/ ) {
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.getValue('table_sys_id'));
//if return something
if (ritm == true) {
var sctask = new GlideRecord('sc_task');
sctask.addQuery('request_item', current.getValue('table_sys_id'));
sctask.query();
while (sc_task.next()) {
current.location = current.request.requested_for.location;
sctask.update();
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 09:37 AM
So the code needs slight adjustment if the requested for field on your sc_task is from sc_req table. This business rule will need to be created on the sc_req table, as the requested for field will be changing there when changed on the sc_task dot walked field.
(function executeRule(current, previous /*null when async*/) {
var userChange = current.requested_for.location;
var requestSysid = current.getUniqueValue();
var scTaskRecord = new GlideRecord('sc_task');
scTaskRecord.addQuery('request', requestSysid);
scTaskRecord.query();
while(scTaskRecord.next()){
scTaskRecord.location = userChange;
scTaskRecord.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 09:37 AM
So the code needs slight adjustment if the requested for field on your sc_task is from sc_req table. This business rule will need to be created on the sc_req table, as the requested for field will be changing there when changed on the sc_task dot walked field.
(function executeRule(current, previous /*null when async*/) {
var userChange = current.requested_for.location;
var requestSysid = current.getUniqueValue();
var scTaskRecord = new GlideRecord('sc_task');
scTaskRecord.addQuery('request', requestSysid);
scTaskRecord.query();
while(scTaskRecord.next()){
scTaskRecord.location = userChange;
scTaskRecord.update();
}
})(current, previous);