Trying to update value of field in table using scripts or business rules

mikestockman
Giga Contributor

I have a table u_enhancement_task that contains:

u_task_type, u_state, u_assigned_to, u_requirements_state, u_requirements_assigned_to

I'm trying to update the value in the u_requirements_state with u_state and u_requirements_assigned_to with u_assigned_to

where u_task_type = "Requirements".

Here's what I have set up using a business rule (not sure this is the best way):

In the Condition field, I have:

current.u_task_type == "Requirements"

In thescript window, I have:

updateRequirementsStateandAssign();

function updateRequirementsStateandAssign() {

var req = new GlideRecord("u_enhancement_task");

req.addActiveQuery();

req.addQuery("u_task_type", "Requirements");

req.query();

while (req.next()) {

    req.setValue(req.requirements_state, current.state);

    req.setValue(req.requirements_assigned_to, current.assigned_to);

  }

}

If I have the When the run set to :before or display,in a FORM it shows correctly, but it doesn't reflect the updates when I list table.

What did I miss?

1 ACCEPTED SOLUTION

Ok, I wouldn't have done this way but it does work


If you want, you can mark the answer as a solution (so people would see the issue has been answered)


View solution in original post

9 REPLIES 9

  Life is good.   I changed my advanced tab to:


condition: current.u_task_type == "Requirements"



setValue(current.u_requirements_state, current.u_state);


setValue(current.u_requirements_assigned_to, current.u_assigned_to);



Thanks for pointing me in the right direction!!


Ok, I wouldn't have done this way but it does work


If you want, you can mark the answer as a solution (so people would see the issue has been answered)


even though it works, i'd really like to hear a better way of doing this. basically, the requirement was to create a spreadsheet with added columns (requirements state, requirements assigned to, etc.) based on each task type (requirement, design,build, QA). The added columns are in a reference table which I would then map into a report before exporting to excel.


amgadmohamed
Kilo Contributor

add req.update(); at the end of the script


I thought I read somewhere that for scripting in business rules, you don't want to use update().   However, I will try it and let you know how it goes.