How to write a business rule to update values in field when you insert values in another field?

skendy
Tera Expert

Hi,

I am trying to do a simple thing (in project mgmt module):

I am inserting some values in a string field (called 'Owner') and I want that in accordance to this values, some values will fill another field (called 'Department'), AUTOMATICALLY.

I know it should be a business rule, but I'm not having success with this script:

if (current.u_owner=="owner_name")

{

      current.u_lead_bus_sub_dept="department_name";

}

Thank you all for any help,

Skender

1 ACCEPTED SOLUTION

BR Details



Active = true


Insert/Update


Before



Script:


if (current.u_owner.getDisplayValue()=="owner_name")


{


current.u_lead_bus_sub_dept="Any string"+ current.department;


}


-Anurag

View solution in original post

14 REPLIES 14

I Wil get back to you soon with an example



Sent from my android device.


BR Details



Active = true


Insert/Update


Before



Script:


if (current.u_owner.getDisplayValue()=="owner_name")


{


current.u_lead_bus_sub_dept="Any string"+ current.department;


}


-Anurag

Kalaiarasan Pus
Giga Sage

You need to use current to access the field you want ..



Ex:



current.u_lead_bus_sub_dept="Any string"+ current.department;




where department is the field you want....


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Skender,



I have created a BR "Set department" on Incident table. You can edit it as per your requirements.


Here is the link for the demo https://demo007.service-now.com/login.do


Username : admin


Password : admin


Thanks,


Yours works perfectly!!!



When I flag insert and update the next time I see them, they are false again...


I do not have also the Advance option...



Anyway, I did exactly the same thing, but I get this debug msg:


Execute before business rules on sys_user:


17:46:19.721: === Skipping 'user query' on sys_user:; condition not satisfied: Condition: gs.getSession().isInteractive() && !gs.hasRole("admin")