this and that

SBM AppScript Use Cases - 03. Auto-Subtasks for Assessors 본문

SBM

SBM AppScript Use Cases - 03. Auto-Subtasks for Assessors

미스터림 2011. 11. 22. 13:50
한번의 트랜지션으로 선택된 Assessors 에 대한 Subtask를 자동으로 일괄 생성한다.
새로운 워크플로우로는 Post-Transition script를 사용한 Regular Transition을 이용한다.

 선택된 Assessors를 알아낸다.

 선택된 각 Assessor를 위해 새로운 Taks 아이템을 생성한다. 그리고 다음과 같이 필드를 매핑한다.:
• Title and Description copied from Widget Change Request
• Item Type to Task
• Task Owner to the Assessor
• Owner to the Assessor
• Parent Widget CR to the TS_ID of the Widget Change Request item
• Submit Date to now
• Submitter to Tech Lead making the transition
• Last State Changer to Tech Lead
• Last State Change Date to now
• Last Modifier to Tech Lead
• Last Modified Date to now
• State to New (from Task workflow)
• Close Date to null

 원래의 Widget Change Request에서 새롭게 생성된 Task 아이템들을 Child Tasks 필드로 지정한다.

주의: 해당 Transition을 여러번 실행하더라도 각 Assessor에게는 오직 하나의 subtask만 갖도록 해야한다.


' Name: createSubtasks
' Function: Read each Assessor chosen in the Assessors multi-user
'    field and create a new Task item in the Issues table the assessor.
' Context: Post-transition for Pick Assessors transition
'
' Date: 03/09/2006
' For use in the TeamTrack TeamScript course examples.

' Require all vars to be declared before use (and then declare some)
Option Explicit

' Multi-user field containing the owners of the sub-tasks
Const USER_LIST_FLD = "ASSESSORS"
' Field in Parent workflow containing links to sub-tasks
Const SUBTASK_FLD = "CHILD_TASKS"
' Field in sub-task workflow containing link to parent
Const CHILD_SUBTASK_FLD = "PAREN_WIDGET_CR"
' Ownership field of the initial state in sub-task workflow
Const TASK_OWNER_FLD = "TASK_OWNER"
' Item type field and the value to set it to...
Const ITEM_TYPE_FLD = "ISSUETYPE"
Const TASK_TYPE = 314
' Sub-task project ID, table ID, and initial state ID
Const PROJECT_ID = 31
Const CHILD_TABLE_ID = 1000
Const NEWSTATEID = 70

Dim objItem, objFields, objField, objNewItem
Dim strTitle, strDescription, strAssessors, strAssessor
Dim strSubtasks

' Get the current item
Set objItem = Shell.Item

' Read title, description, and assessor fields
Set objFields = objItem.Fields()
Set objField = objFields.FindField(USER_LIST_FLD)
objField.GetValue strAssessors

Set objField = objFields.FindField("TITLE")
objField.GetValue strTitle

Set objField = objFields.FindField("DESCRIPTION")
objField.GetValue strDescription

' Find out if there are any assessors. An empty field is "," otherwise it is a comma 
' separated list of user ids with leading and trailing commas.
If strAssessors <> "," Then
  Dim nStart, nEnd, nId, nLength, nNewId, strNewIds
  nStart = 2
  nLength = Len(strAssessors)
  nEnd = nStart
'  Call Ext.LogInfoMsg("Assessors: "&strAssessors&" nEnd "&nEnd&" Len "&nLength)
  do while nStart <= nLength
      'Use VB like functions to parse the list of users
      nEnd = InStr(nStart,strAssessors,",")
      nId = Mid(strAssessors, nStart, nEnd - nStart)
      nNewId = CreateSubtask(nId, strTitle, strDescription)
'      Call Ext.LogInfoMsg("Id: "&nId)
      strNewIds = strNewIds & nNewId & ","
      
      nStart = nEnd + 1
  Loop

  'update the current record with the newly created subtask
  Set objField = objFields.FindField(SUBTASK_FLD)
  objField.GetValue strSubtasks
  If strSubtasks = ",," then
    strSubtasks = ","
  End If
  strSubtasks = strSubtasks & strNewIds
  objField.SetValue strSubtasks
End If

' This function creates a new record and returns the new id
Function CreateSubtask(nFId, strFTitle, strFDescription)
  Dim objNew
  Set objNew = Ext.CreateVarRecord(CHILD_TABLE_ID)
  call objNew.SetFieldValue("TITLE",strFTitle)
  call objNew.SetFieldValue("DESCRIPTION", strFDescription)
  call objNew.SetFieldValue(ITEM_TYPE_FLD,TASK_TYPE)
  call objNew.SetFieldValue(TASK_OWNER_FLD,nFId)
  call objNew.SetFieldValue("OWNER",nFId)
  call objNew.SetFieldValue(CHILD_SUBTASK_FLD,objItem.getid())

  'Set the system fields
  Call objNew.SetFieldValue("SUBMITDATE", Ext.DateToDBLong(now))
  Call objNew.SetFieldValue("SUBMITTER", Shell.User.GetId())
  Call objNew.SetFieldValue("LASTSTATECHANGER",Shell.User.GetId())
  Call objNew.SetFieldValue("LASTSTATECHANGEDATE", Ext.DateToDBLong(now))
  Call objNew.SetFieldValue("LASTMODIFIER", Shell.User.GetId())
  Call objNew.SetFieldValue("LASTMODIFIEDDATE", Ext.DateToDBLong(now))
  Call objNew.SetFieldValue("PROJECTID", PROJECT_ID)
  Call objNew.SetFieldValue("STATE", NEWSTATEID)
  Call objNew.SetFieldValue("CLOSEDATE", NULL)
  
  ' Create (add)  the new record in the database.
  CreateSubtask = objNew.Add()
End Function

Comments