How can I update a field on a Request Item when the Task is closed?

BHunt
Kilo Contributor

I am trying to build out a request item that creates 1 task at a time. The user needs to have an option though to create a new task for another group if the request requires additional effort from that group to complete it. I have added a field to the Task form for the user to specify which group the next task should be assigned to. I have also added the same field to the Request Item form as well as an additional field which is a Yes/No to state if additional effort is required to complete the task. By default the "Additional Effort Required" field would be NO, but if a person adds a group to the Additional Effort Group field on the Task, and when they close it, a Business rule would check that field. If the field on the task is not empty, add the group to the Additional Effort Group field from the Task form, to the Request Item, and change the "Additional Effort Required" Field on the Request Item to Yes from No. The workflow would then use that Yes value to create a new Task and assign it to the specified group.

That is how things are supposed work anyway...
What I'm stuck on is getting the fields on the Request Item form to be updated. Disclaimer: I am learning JavaScript while learning JavaScript for ServiceNow so I'm sure this is something that is crazy easy, I just don't know how to do it. Below is the Business Rule script I have. Could someone point me in the right direction to get this to work? Thanks!

//gs.addInfoMessage("Current Request Item: " + current.request_item.number.u_additional_effort);
//gs.addInfoMessage("Current Task: " + current.number);
//gs.addInfoMessage("Current Assign Group: " + current.u_assigning_to_group);

if(current.u_assigning_to_group==""){

var addtlEfrt = current.request_item.u_additional_effort;
var addtlGrp = current.u_assigning_to_group;
gs.addInfoMessage("Current Additional Group: " + addtlGrp);

current.request_item.u_additional_effort = "no";
gs.addInfoMessage("No Additional Effort: " + addtlEfrt);
gs.addInfoMessage("No Additional Group: " + addtlGrp);

}
else{

current.request_item.u_additional_effort = "yes";
current.request_item.u_additional_group = addtlGrp;
gs.addInfoMessage("Additional Effort: " + current.request_item.u_additional_effort);
gs.addInfoMessage("Additional Group: " + addtlGrp);
}

2 REPLIES 2

Admin Pro
Tera Contributor

I am not going into saying that there are better ways to do this as obviously I don't know the whole story. However, assuming you are running this as a before business rule on "sc_task" table, then you need to query the "sc_req_item" in order to be able to update fields value on that table. Having said all of that, then your script would look like this:



var item = new GlideRecord('sc_req_item');
item.addQuery('sys_id' , current.request_item);//finds the parent request item for the current catalog task
item.query();
while(item.next()){
item.u_additional_effort = "no";
item.update();
}

This should help you get going. You can also take a look at this wiki article which talks in more detail about Glide Record.
http://wiki.servicenow.com/index.php?title=GlideRecord


BHunt
Kilo Contributor

Yeah, I'm still learning JavaScript, and was able to figure out exactly what you proposed after posting this question. Thank you for your response!