business rule to prevent closing of a record if child task records are not closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 08:01 AM
hi all,
In a custom scoped app "Feedback", I have a custom table (extended off Task) for feedback records (let's call this the parent table). I have a 2nd custom table (also extended off Task) for the tasks assigned to a feedback record (let's call this the child table). I configured the 2nd table to be a related list on the records of the 1st table...so that tasks can be created and assigned associated with a feedback record. I need a business rule to make it so the State of the parent feedback record cannot be closed if any of the associated tasks in the related list on a particular record are not closed.
I'm struggling a little with the script...thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 08:28 AM
ok got it. here's what I have so far.
and this is my script...thinking I'm close?
var gr = new GlideRecord('x_cur_oc_feedback_tasks');
gr.addQuery('parent', current.sys_id); //Repalce parent with exact field column name of field on child table which references parent table
gr.addQuery('state', '!=', closed); //Here replace state with exact column name of state on child table and with exact value
gr.query();
while(gr.next()){
current.setAbortAction(true); //abort the record
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 08:31 AM
and here is what a child task record looks like
it's that "State" field that needs to be set to either "Closed complete", "Closed incomplete", or "Closed skipped" for the "State" field in the parent Feedback record to be able to be set to "Closed incomplete", "Closed incomplete", or "Closed skipped".
so for this line of code
gr.addQuery('parent', current.sys_id); //Replace parent with exact field column name of field on child table which references parent table
would 'parent' actually be the field we want here...and as well I would guess that field would need to have an entry, and that entry would need to be the number of the parent feedback record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 08:39 AM
I think I see my issue. The "Parent" field on the child task record is not properly connected to the parent "Feedback" record. When turn off the "read only" dictionary override, and then try to just enter the correct associated "Feedback" record's Number, it does not allow that entry. I can only chose and entry from the same child task table. So I think my problem starts here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 10:53 AM
OK I fixed my issue with the "Parent" field on the child task record, so it is now populating properly and confirming the relationship between the child task record and the parent feedback record.
so for the business rules, my script is looking like this so far:
var gr = new GlideRecord('x_cur_oc_feedback_tasks');
gr.addQuery('parent', current.sys_id); //Repalce parent with exact field column name of field on child table which references parent table
gr.addQuery('state', '!=Closed', closed); //Here replace state with exact column name of state on child table and with exact value
gr.query();
while(gr.next()){
current.setAbortAction(true); //abort the record
}
one thing, there are 3 states of "closed" for the child task record, they are "Closed Complete", "Closed Incomplete", and "Closed Skipped". Any of these 3 choices satisfy the condition of the child task record being "closed". Does this change my script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 11:17 AM
I'm thinking I have this line wrong
gr.addQuery('state', '!=', 1); //Here replace state with exact column name of state on child table and with exact value
'state' is the name of the field on the child table (so that looks correct)
when you say "exact value", are you talking about the "Closed Complete", "Closed Incomplete", and "Closed Skipped" values? and would those replace the "!=" ?