- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 01:53 PM
Seems like this should be a simple thing, but I have yet to find a solution, so I'm posting the question.
Our process is this.
Demand -> creates -> Project -> creates -> Change Request
The demand has a reference field for Project and Change Request to provide on screen status of the state of each of them
The project has a reference field for Demand and Change Request
The change request has a reference field for Demand and Project
What I'm trying to do is trigger a business rule when the Change Request state changes to "Closed"
I want this rule to run a script to change the state fields on the related Demand and Project records to a Closed state. (For this example, let's say that the state == 3)
I've tried a couple of options, but not getting anything to change the state.
scripting level = rookie
Here was an attempt that did not work:
var relproject = new GlideRecord("pm_project");
relproject.addQuery("change_request", current.sys_id);
relproject.query();
while (relproject.next()) {
relproject.state.setValue(3);
relproject.update();
}
var reldemand = new GlideRecord("dmn_demand");
reldemand.addQuery("dmn_demand", current.sys_id);
reldemand.query();
while (reldemand.next()) {
reldemand.state.setValue(3);
reldemand.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 07:34 AM
Thank you so much Sholke for pointing me in the right direction. I used your example, but couldn't get the Demand state to update. I verified the reference field names and it looks like it should work, but just wouldn't. My thought was that maybe the demand record was not updating after the state field was changed. I tried to dot walk an update command, but it didn't seem to work.
I ended up using the same syntax that you provided to perform a get on the dmn_demand table and update the state there and it works. Here's what my Business Rule script looks like.
(function executeRule(current, previous /*null when async*/) {
var prj = new GlideRecord("pm_project");
prj.get(current.u_project);
prj.state = '3';
prj.update();
var dmn = new GlideRecord("dmn_demand");
dmn.get(current.u_demand);
dmn.state = '3';
dmn.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 07:35 AM
Thanks for your suggestion. Since we have a one to one relationship with Demand-Project-Change, I went with the route below. I can see how your suggestion would help if we had many to one working. Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 06:46 PM
var relproject = new GlideRecord("pm_project");
relproject.addQuery("change_request", current.sys_id); // Make sure change_request field name is correct
relproject.query();
while (relproject.next()) {
relproject.setValue('state', 3);
relproject.update();
}
var reldemand = new GlideRecord("dmn_demand");
reldemand.addQuery("u_change_request", current.sys_id); // please update the field name of change request here
reldemand.query();
while (reldemand.next()) {
reldemand.setValue('state', 3);
reldemand.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 10:47 PM
Hi,
I had a similar requirement.Can you try the script mentioned below:
Write a After Update Business Rule on the Change Request Table with filter conditions as "State Changes to Closed" and the script below:
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var prj = new GlideRecord('pm_project');
prj.get(current.u_project); //u_project is the reference field on the Change Request Table
prj.state = '9'; //Replace '9' with your Closed/Completed Value
prj.u_demand.state = '3'; //u_demand is the field on the Project table and can dot walkin to update the State field
prj.update();
})(current, previous);
Replace your fields accordingly and it should work for you.
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 07:34 AM
Thank you so much Sholke for pointing me in the right direction. I used your example, but couldn't get the Demand state to update. I verified the reference field names and it looks like it should work, but just wouldn't. My thought was that maybe the demand record was not updating after the state field was changed. I tried to dot walk an update command, but it didn't seem to work.
I ended up using the same syntax that you provided to perform a get on the dmn_demand table and update the state there and it works. Here's what my Business Rule script looks like.
(function executeRule(current, previous /*null when async*/) {
var prj = new GlideRecord("pm_project");
prj.get(current.u_project);
prj.state = '3';
prj.update();
var dmn = new GlideRecord("dmn_demand");
dmn.get(current.u_demand);
dmn.state = '3';
dmn.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2017 08:53 AM
Hi,
Can you help me by providing the exact fields as mentioned below:
1) Name of Project Field(Referencing to Project Table) on Change Request Table.
2) Name of Demand Field(Referencing to Demand Table) on Project Table.
Regards,
Shloke
Regards,
Shloke