Using UI action to update multiple child records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 01:24 PM
Hello everyone,
Thank you in advance for your interest and assistance! I am trying to create a UI action that will live on the project record that if clicked will update a custom field on it's associated cost plans. I am combing through existing UI actions for guidance, if anyone knows of any threads or has any suggestions on how I can best accomplish this I would be incredibly grateful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 03:05 PM
Hello,
Thank you very much for taking the time to respond! I have been working at this a bit and I think where I need the script to live is in a business rule, not necessarily the UI action. The business rule would seek to set the custom field value on all the cost plans related to the project. Would this code work in such a set up?
I attempted this script in a business rule
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("cost_plan");
gr.addQuery("task", current.sys_id());
gr.setValue("u_funding_approval_state", "Pending");
gr.updateMultiple();
})(current, previous);
The rule triggers when a specific state is set on the project record. Unfortunately nothing happened, currently I am running this rule on the project pm_project table, is this a problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 05:42 PM
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("cost_plan");
gr.addQuery("task", current.task);
gr.query();
while(gr.next()){
gr.u_funding_approval_state = "Pending state number here";
gr.update();
}
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 10:02 AM
Hello Prateek,
Thank you very much for your assistance, unfortunately it is still not working. I would like to clairify, the state that I am using is a custom field, it is not the true state field so the word state is a bit of a misnomer. Does that make a difference in how this should be crafted?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 10:52 AM
It shouldn't be the issue.
Can you show us on what conditions you are trying to run this BR.
Can you also see if the error message is popping up after updating the code to below.
One more thing what is the database value for pending state for your u_funding_approval_state field
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("cost_plan");
gr.addQuery("task", current.task);
gr.query();
while(gr.next()){
gs.addErrorMessage('BR is executing');
gr.u_funding_approval_state = "Pending state number here";
gr.update();
}
})(current, previous);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2019 11:05 AM
Hello Prateek,
The business rule is set to run when Funding State Approval changes to Pending before update order 100. The database value for pending is "1".
The kick off for this is a UI action that might be part of the problem. Though the UI action is setting the fields value it is not updating the record at the same time. It's client callable with onclick: propose();
function propose(){
var funding = new GlideRecord("u_funding_approval_state");
g_form.setValue('u_funding_approval_state','Pending');
current.update();
action.setRedirectURL(current);
}