Create a view with a calculated column to be used in Clarify CRM and Dovetail Agent.
Our customer would like to query all the cases including a column with a calculated number of “open” subcases related to each case record. They want to query for all of the cases that have any open subcases. A normal view would not work because it cannot calculate the count of related object with specified condition.
Steps taken.
1. We showed it could be done in SQL (See SQL below). Note the nested SQL statement to calculate the number of open subcases.
select c.objid, c.id_number, cond.title, cond.title, (SELECT count(*) FROM table_subcase sc INNER JOIN table_condition sc_cond ON sc_cond.objid = sc.subc_state2condition WHERE sc.subcase2case = c.objid AND sc_cond.title LIKE 'OPEN%') as open_subcase_count FROM table_case c INNER JOIN table_condition cond ON cond.objid = c.case_state2condition
2. Created the following SchemaEditor SchemaScript.
Case identifiers and condition and the count open subcases for the case select c.objid, c.id_number, cond.title, cond.s_title, (SELECT count(*) FROM table_subcase sc INNER JOIN table_condition sc_cond ON sc_cond.objid = sc.subc_state2condition WHERE sc.subcase2case = c.objid AND sc_cond.s_title LIKE 'OPEN%') as open_subcase_count FROM table_case c INNER JOIN table_condition cond ON cond.objid = c.case_state2condition 255 false 80 true 80
3. Previewed and applied the schema changes against the Amdocs/Clarify database using the Dovetail SchemaEditor.
- Preview schema changes: SchemaEditor.exe -p
- Apply schema changes: SchemaEditor.exe -a
4. Here is the code that using the new view within the Dovetail Agent application.
<% =boCase('case_id_number') + "" %> | <% =boCase('case_cond_title') + "" %> | <% =boCase('open_subcase_count') + "" %> | <% boCase.MoveNext(); } %>