- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-28-2022 01:50 AM
Hi Team,
i need to build a businessrule on Incident and requested item tables or on Interaction table to check all the related tasks are closed or not before closing the interaction.
i.e.
1. Create an Interaction.
2. create an Incident from that Interaction.
3. create a request from the same interaction.
4. Close the Incident. Here my Businessrule should check whether remaing tasks in the interaction is closed or not. if closed, close the interaction along with the incident. if not, interaction should stay in work in progress state.
5. Close the request. Here my Businessrule should check whether remaing tasks in the interaction is closed or not. if closed, close the interaction along with the requested item. if not, interaction should stay in work in progress state.
6. Once all related tasks are complete interaction should close automatically.
Note: we can create multiple incidents, requests from a single interaction.
my issue building a business rule is, there is no reference field refer to Interaction table is available in Incident and Requested Item Tables. Related Tasks are getting populated in interaction via 'Related Tasks' Relationship. and this relationship is using 'interaction_related_record' table and Interaction and Task tables to pull the related tasks.
i don't have enough experience to build this kind of queries and script to check these kind of scenarios.
can anyone please provide the sample script for it.
Thanks in advance.
Hari Kishan.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-07-2022 10:28 PM
Hi Hari,
it would require two business rules. one is on the Task table and another one on the interaction related record table.
1. create a field called 'Interaction(u_interaction) on the Task table.
2. Create a Business rule on interaction related record table (before insert update)to copy the interaction field to task table.
3. Create a business rule on task table (after update and Active changes to false)to set the interaction to closed complete once all related task are in active false state.
(function executeRule(current, previous /*null when async*/) {
var result = [];
var array = [];
var ref = [7,3];
var gr = new GlideRecord ('task');
gr.addQuery('u_interaction',current.u_interaction);
gr.query();
while (gr.next())
{
array.push(gr.state);
}
if(array.length > 0)
{
for(var i=0;i<array.length;i++)
{
var arrayUtil = new ArrayUtil();
if(arrayUtil.indexOf(ref, array[i])==-1)
{
result.push(array[i]);
}
}
}
if(result.length == 0)
{
var inter = new GlideRecord ('interaction');
inter.addQuery('sys_id',current.u_interaction);
inter.query();
if(inter.next())
{
inter.state='closed_complete';
inter.update();
}
}
})(current, previous);
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('task');
gr.addQuery('sys_id', current.document_id);
gr.query();
if(gr.next()){
gr.u_interaction = current.interaction;
gr.update();
}
var gr1 = new GlideRecord('interaction');
gr1.addQuery('sys_id', current.interaction);
gr1.query();
if(gr1.next()){
gr1.state = 'work_in_progress';
gr1.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-03-2023 09:05 PM - edited ā09-03-2023 10:41 PM
@Tuellmom Hello,
Write a scheduled job in case you want to auto-close everyday. If you want to auto-close the previous interaction bulk-records write a fix-script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-18-2024 03:36 AM
Hi Hari,
I have created a custom state in interaction table. and also I have one UI Action created in service operation workspace. Upon clicking of that UI Action, I want the state to be moved to the custom state created. But for me The OOB business Rule "Interaction - Closed" is overriding that configuration and moving the state to closed complete. I dont want to deactivate that business rule since I am using that. I have gone through the scripts inside the business rule, but i dont see any state setting configurations. Kindly if you have any solutions. Help me out