Skip to content

Instantly share code, notes, and snippets.

@gsherman
Last active October 10, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsherman/3691225 to your computer and use it in GitHub Desktop.
Save gsherman/3691225 to your computer and use it in GitHub Desktop.
Make "Change Priority" a Business Rule Event and Activity Log entry
Modify the control named "SEL_EVENT"
'Add an Item of "Change Priority"
Add a Path of CASE
Add a Value List Name of USER1002
Save it & Add this form to the proper Resource Configs
OBJECT TYPE="gbst_elm", NAME=x_new_activity UNIQUE_FIELD=title,rank
UNIQUE_RELATION=gbst_elm2gbst_lst
FIELDS
title ="Priority Changed";
rank=92010;
state=0;
END_FIELDS
RELATIONS
TO_NAME=activity_name REL="gbst_elm2gbst_lst";
END_RELATIONS
END_OBJECT NAME=x_new_activity
REFERENCE TYPE="gbst_lst", NAME=activity_name UNIQUE_FIELD=title
FIELDS
title ="Activity Name";
END_FIELDS
RELATIONS
END_RELATIONS
END_REFERENCE NAME=activity_name
'Merge this CB code to Case Edit, Form 420:
'At the top of the module, add:
'Function Declarations
Declare Sub AddActLogEntry(bs as BulkSave, recCase as Record, ActType as String)
'Define Private Variables
Private OldPriorityStr As String
'Add the following to Form Load:
Sub Form_Load()
'Save the Priority
OldPriorityStr = Cobj_RESPPRTY_CHOICE.Contents
End Sub
'Add the following to Form_Save1:
Sub Form_Save1(bs as BulkSave)
Dim recCase as Record
Dim NewPriorityStr As String
Set recCase = Cobj_CASE_OBJ.Contents
NewPriorityStr = Cobj_RESPPRTY_CHOICE.Contents
'See if the Priority Changed.
'If it did, add an Act Log & a Time Bomb
If OldPriorityStr <> NewPriorityStr Then
Call AddActLogEntry(bs,recCase,"CHANGE_PRIORITY")
'Reset the OldSPriority
OldPriorityStr = Cobj_RESPPRTY_CHOICE.Contents
End If
'Add the following to Form_Save2:
Sub Form_Save2(bs As BulkSave)
'Update my time bomb with the act_entry objid
Dim recTimeBomb as Record
Dim recActEntry as Record
Dim index as Integer
Dim ActEntryObjid as Long
ActEntryObjid = 0
If bs.CountByType("time_bomb") > 0 Then
If bs.CountByType("act_entry") > 0 Then
'Cycle thru all the act_entry records til I get the right one
For index = 0 to bs.CountByType("act_entry") - 1
Set recActEntry = bs.GetRecordByIndex(index, "act_entry")
If recActEntry.GetField("act_code") = 92010 Then
'This is the correct one!
ActEntryObjid = recActEntry.GetField("objid")
End If
Next index
If ActEntryObjid > 0 Then
'Cycle thru all the time bomb records til I get the right one
For index = 0 to bs.CountByType("time_bomb") - 1
Set recTimeBomb = bs.GetRecordByIndex(index, "time_bomb")
If recTimeBomb.GetField("flags") = 65667074 Then
'This is the correct one!
recTimeBomb.SetField "time_period", ActEntryObjid
End If
Next index
End If
End If
End If
End Sub
'And add the following routine anywhere in your 420 code file:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Add an Act Log & a Time Bomb Sub '''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub AddActLogEntry(bs as BulkSave, recCase as Record, EntryType as String)
Dim AEBulkSave As New BulkSave
Dim AERecord As New Record
Dim actCode As Long
Dim addnlInfo As String
Dim currDateTime As String
Dim gbst_list as New List
Dim gbst_rec as Record
Dim br as New BulkRetrieve
Dim CaseObjid as Long
Dim NewPriorityStr as String
Dim TimeBombFlags as Long
Dim recTimeBomb as New Record
currDateTime = CStr(App.CurrentDate)
NewPriorityStr = Cobj_RESPPRTY_CHOICE.Contents
CaseObjid = recCase.GetField("objid")
Select Case EntryType
Case "CHANGE_PRIORITY"
actCode = 92010 'This is my custom act code
TimeBombFlags = 65667074 ' (1002 *65536) + 2 = 65667074
addnlInfo = "Priority Changed from " + OldPriorityStr + _
" to " + NewPriorityStr
Case Else 'Unknown
Exit Sub
End Select
'We need to get the gbst_elm for this actCode
br.SimpleQuery 0, "gbst_elm"
br.AppendFilter 0, "rank", cbEqual, actCode
br.RetrieveRecords
Set gbst_list = br.GetRecordList(0)
br.Clear
If gbst_list.Count > 0 Then
Set gbst_rec = gbst_list.ItemByIndex(0)
Else
Exit Sub
End If
'Build the Act Entry Record
AERecord.RecordType = "act_entry"
AERecord.SetField "act_code", actCode
AERecord.SetField "entry_time", currDateTime
AERecord.SetField "addnl_info", addnlInfo
bs.InsertRecord AERecord
bs.RelateRecordsToID AERecord, "user", App.UserObjid, "act_entry2user"
bs.RelateRecordsToID AERecord, "case", CaseObjid, "act_entry2case"
bs.RelateRecords AERecord, gbst_rec, "entry_name2gbst_elm"
'Build a Time Bomb Record as well
recTimeBomb.RecordType = "time_bomb"
'Set the escalate_time to a time in the past so the bomb fires immediately
recTimeBomb.SetField "escalate_time", Format(DateAdd("yyyy", -10, CDate(App.CurrentDate)), "mm/dd/yy hh:nn:ss")
recTimeBomb.SetField "end_time", currDateTime
recTimeBomb.SetField "focus_lowid", recCase.GetField("objid")
recTimeBomb.SetField "focus_type", 0
recTimeBomb.SetField "time_period", 0
recTimeBomb.SetField "flags", TimeBombFlags
bs.InsertRecord recTimeBomb
bs.RelateRecordsToID recTimeBomb, "employee", App.EmployeeObjid, "cmit_creator2employee"
End Sub
Dovetail Agent code: Pass the original case priority as a hidden field on case.asp
<input type="hidden" id="originalPriority" name="originalPriority" value="<%=lPriority%>"/>
DovetailAgent code:
2. Create a function that can add a new Activity Log entry, on case2.asp
//Create a custom act entry
function CreateActEntry(act_code,addnl_info){
boAct_Entry.AddNew();
boAct_Entry('act_code') = act_code; // 92010 will be ussed for my Change Priority event act_code;
boAct_Entry('addnl_info') = addnl_info;
boAct_Entry('entry_time') = -999; //now
boAct_Entry('entry_name2gbst_elm') = FCApp.GetGbstElmRankObjid("Activity Name",act_code); //278437786; //
boAct_Entry('act_entry2user') = FCSession.Item('user.id');
boAct_Entry('act_entry2case') = case_objid;
boAct_Entry.Update();
}
-------------------------------------------------------
3. Compare the old and new priority values. If the priority has changed, call the function to create an Act Entry record.
var newPriority = Request.Form("Priority") - 0;
var originalPriority = Request.Form("originalPriority").Item - 0;
var emp_id = FCSession.Item("employee.id");
//If the Priority changed, add an act entry
if (newPriority != originalPriority){
//Create an act entry generic object
var boAct_Entry = FCSession.CreateGeneric("act_entry");
var addnl_info = "Priority Changed from " + originalPriority + " to " + newPriority;
CreateActEntry(92010, addnl_info);
//Then create a Time Bomb generic object
var boTB = FCSession.CreateGeneric('time_bomb');
//time bomb for the Priority Change activity
boTB.AddNew();
boTB("escalate_time") = -999;
boTB("end_time") = -999;
if(FCApp.schema_rev >= 55){ //55 = clarify_10
boTB("creation_time") = -999;
}
boTB("focus_type") = 0;
boTB("flags") = 65667074;
boTB.RelateById(emp_id,"cmit_creator2employee");
boTB("focus_lowid")= case_objid;
boTB("time_period")= boAct_Entry.Id;
boTB.Update();
boTB.CloseGeneric();
}
4. Close the generic
At the end of the case2.asp page, add:
boAct_Entry = null;
Create the Clarify Business Rule
1. Restart rulemanager, so the new SEL_EVENT is recognized
2. Create a new Business Rule, using Change Priority as the Start On Event.
*/optional */ If you only want a notification when the priority is changed to specific value, enter that value on the Conditions page. example: Priority = 1
@gsherman
Copy link
Author

This is example code for adding an activity log (and time_bomb) when the priority is changed on a case, which allows business rules to be fired on this activity.
This example includes code for both the Clarify Classic Client and Dovetail Agent.

This code was shared by one of our customers.

@gsherman
Copy link
Author

This code was shared by one of our customers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment