Unable to populate Requested for.location in SCTASK Location field when Requested for in SCTASK changes

Gian1
Tera Contributor

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);

1 ACCEPTED SOLUTION

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);
If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

5 REPLIES 5

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);
If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!