Name

global.ScrumAjaxTaskProducer

Description

(1) Extracts the parameters that have been received from the client (2) Inserts as many types and counts of scrum tasks as requested

Script

var ScrumAjaxTaskProducer = Class.create();

ScrumAjaxTaskProducer.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 createTasks: function () {
    var mapDetails = this._getLabels("rm_scrum_task", "type");
    var strSysId = this.getParameter("sysparm_sys_id");
    var recTasks = new GlideRecord("rm_scrum_task");
    var recStory = new GlideRecord("rm_story");
    recStory.get(strSysId);
    for (var strTaskType in mapDetails) {
       var nCount = parseInt(this.getParameter("sysparm_" + strTaskType), 10);
       for (var nSlot = 0; nSlot < nCount; ++nSlot) {
          recTasks.initialize();
          recTasks.short_description = "ToDo...";
          recTasks.state = -6;   // DRAFT
          recTasks.type = mapDetails[strTaskType];
          recTasks.parent = recTasks.story = strSysId;
          recTasks.assignment_group = recStory.assignment_group;
          recTasks.sys_domain = recStory.sys_domain;
          recTasks.insert();
       }
    }
 },

_getLabels: function(strTable, strAttribute) {
    var map = {};
    var choices = new GlideSysChoice(strTable, strAttribute);
    var recChoices = choices.getChoices();
    while (recChoices.next()) {
  	  if (recChoices.getValue("inactive") === "1")
  		  continue;
  	  map[(recChoices.label + "")] = recChoices.value + "";
    }
    return map;
  },
  
  /* Exposed through glide ajax to return type of scrum task. */
  getLabels: function() {
      var table = this.getParameter("sysparm_table");
      var attribute = this.getParameter("sysparm_attribute");
      var resultObj = this._getLabels(table, attribute);
      var json = new JSON();
      return json.encode(resultObj);
  },
  
  /**
   * Prevent public access to this processor
   */
  isPublic: function() {
      return false;
  }
});

Sys ID

e0962731ef321000a7450fa3f822566e

Offical Documentation

Official Docs: