Business Rule not detecting change with a dot walked field

SC10
Kilo Guru

On my Project table form, I have dot walked to the Demand table's field of "Project Sponsor".

Creating a new Business Rule, I would like to update a value on my Project record when this dot walked field changes value:

BRissue1.png

(Note: I have since turned off the "advanced" condition, and am simply using the filter condition on "When to run")

BRissue2.png

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Shane,



The idea with Business rules is they detect changes on the record they are watching. In your case, you are asking to watch the pm_project table for updates. yet your condition is also asking "If something changes on the demand table..."



You see the conundrum? Technically, nothing changed on the pm_project table to trigger this business rule. You are looking for a business rule on the demand table which then needs to update the (child) project. That's going to require a bit of script and, if you have multiple child projects under that one demand, they are all going to get updated.


View solution in original post

24 REPLIES 24

The issue is that I want "Task For" to be on the records of my Demand table, and my Project table, for reporting purposes.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Thanks Shane for the update. Then the best option is to create a before BR on pm_project table and copy the field value to be same as of Demand.


Please let me know if you have any questions.


Do you want to COPY the value of the Task For from demand to project? That's pretty easy, but requires scripting again.


Yes which I am fine with doing, it's the other way that is giving me pause.



When our Demands become Projects, we are no longer relying on the "Requested for" field of the Demand to set a "Task for", instead the Project is now really for the "Project Manager" (which is Demand.Project Manager on my Project form, which is led me down this rabbit hole in the first place...).


OK, still trying to wrap my head around the problem and the simplest solution.



Do you've placed a dot-walked field on the form for Demand.Project Manager? And you want to see if that project manager changes, then... do something,



Am I right?



The best way to do that is with a business rule on the demand table. Watch THAT table and see if the field changes, then find all impacted projects (tied to that demand) and affect changed there.



This is an AFTER business rule on the demand table. Something like this: ***WARNING UNTESTED***. Check all bold fields and change them to the proper names for your table/fields as needed.



Name: Update Projects PM


Active: true


Table: Demand (dmn_demand)


Update: true


Insert: false (new demands won't have an associated project)


Advanced: true


When: after


Condition: current.project_manager.changes()  


Script:



var prj = new GlideRecord('pm_project');


prj.addQuery('demand', current.sys_id); // Find all projects related to this demand


prj.query();



while (prj.next()) {


        prj.project_manager = current.getValue('project_manager'); // Copy over the PM


        prj.update();


}



Business Rules - ServiceNow Wiki


Business Rules Best Practices - ServiceNow Wiki