2 Replies · Latest reply on May 19, 2017 4:49 PM by Blaze Llanos

    Help Accessing Templates via UI Page

      i need help accessing legal templates via a UI page. The idea is to access relatively easily templates for Legal Tasks

       

      So far I have the following:

       

      UI Action - Add Legal Task - Functioning Correctly

      UI Page - Functioning about 50% correctly

      Script Include - Functioning about 50% correctly.

       

       

      Here are the respective Scripts

       

      UI Action:

      Name: Add Legal Task

      Table: Legal Request

       

      Active

      Show Update

      Client

       

      OnClick: clickActivate()

      Condition: !current.isNewrecord() && gs.hasRole('admin')

       

      Script

      function clickActivate() {

         sysId = gel('sys_uniqueValue').value;

       

       

        // bring up the UI page for the ranges entry...

        dlog = new GlideDialogWindow('add_legal_task', false, 620);

        dlog.setTitle('Add task');

        dlog.setPreference('sn_sm_legal_request_id', sysId);

        dlog.setPreference('sn_sm_legal_request_table', 'sn_sm_legal_request');

        dlog.render();

      }

       

       

      UI Page:

      Name: add legal task

      Category: General

      Application: Global

       

      HTML(XML)

       

      <g:requires name="styles/heisenberg/heisenberg_all.css" includes="true" />

      <g:requires name="scripts/lib/jquery_includes.js" />

      <g:requires name="scripts/heisenberg/heisenberg_all.js" />

       

       

      <g:evaluate var="jvar_sd_id">

         var sdr_id = "${RP.getWindowProperties().get('sn_sm_legal_request_id')}";

         sn_sm_legal_request_id;

      </g:evaluate>

      <g:evaluate var="jvar_sd_table">

         var sdr_table = "${RP.getWindowProperties().get('sn_sm_legal_request_table')}";

         sn_sm_legal_request_table;

      </g:evaluate>

      <g:evaluate var="jvar_tasktemplate_list" jelly="true">

        var taskTemplateList = [];

        var taskTemplateGR = new GlideRecord('sn_sm_legal_task_template');

        taskTemplateGR.addQuery('u_active', 'true');

        taskTemplateGR.query();

        while(taskTemplateGR.next()) {

        taskTemplateList.push({

        sys_id: taskTemplateGR.sys_id+"",

        number: taskTemplateGR.u_number+"",

        state: taskTemplateGR.u_state.getDisplayValue()+"",

        type: taskTemplateGR.u_task_type.getDisplayValue()+"",

        short_description: taskTemplateGR.u_short_description+""

        });

        }

        taskTemplateList;

      </g:evaluate>

      <div class="popup_dialog">

        <div class="popup_dialog_description">

        <p>Please select the type of task you would like to add:</p>

        </div>

        <select id='taskTemplateSelectField' class='form-control select2' name='taskTemplateSelectField'>

        <j:forEach items="${taskTemplateList}" var="jvar_tasktemplate_instance">

        <g:evaluate var="jvar_sysid" jelly="true" expression="jelly.jvar_tasktemplate_instance.sys_id" />

        <g:evaluate var="jvar_number" jelly="true" expression="jelly.jvar_tasktemplate_instance.number" />

        <g:evaluate var="jvar_state" jelly="true" expression="jelly.jvar_tasktemplate_instance.state" />

        <g:evaluate var="jvar_type" jelly="true" expression="jelly.jvar_tasktemplate_instance.type" />

        <g:evaluate var="jvar_short_desc" jelly="true" expression="jelly.jvar_tasktemplate_instance.short_description" />

        <option value="${jvar_sysid}">${jvar_short_desc} (set Legal state to ${jvar_state}) | Type: ${jvar_type}</option>

        </j:forEach>

        </select>

        <br/><br/>

        <input class="button" onclick="onAddTask();" type="submit" name="ast_button"      value="Add"  />

        <input class="button" onclick="onInvCancel();"  type="submit" name="cancel_button"  value="Cancel"       />

       

      </div>

      <script>

          function onInvCancel() {

              dlog.destroy();

          }

       

        function onAddTask() {

        <!-- alert('option selected: ' + getTemplateSelected()); -->

            var ga = new GlideAjax('AddLegalTask');

            ga.addParam( 'sysparm_name',    'addTask'      );

            ga.addParam( 'sysparm_templateid',  getTemplateSelected() );

            ga.addParam( 'sysparm_sdr_id',   '${sdr_id}'          );

            ga.addParam( 'sysparm_sdr_table','${sdr_table}'       );

            ga.getXMLWait();

         var taskid = ga.getAnswer();

            dlog.destroy();

         if (taskid)

               self.location = 'sn_sm_legal_task.do?sysparm_query=sys_id=' + taskid;

         else

            self.location = '${sn_sm_legal_request_table}.do?sysparm_query=sys_id=${sdr_id}';

        }

       

        function getTemplateSelected() {

        var select = gel("taskTemplateSelectField");

        return select.options[select.options.selectedIndex].value;

        }

      </script>

       

      Script Include:

       

      Name: AddLegalTask

      Client Callable

      Accessible from

      Accessible from: All Application Scopes

       

      Script

       

      var AddLegalTask = Class.create();

       

       

      AddLegalTask.prototype = Object.extendsObject(AbstractAjaxProcessor, {

          ajaxFunction_addTask: function() {

        var templateid = this.getParameter('sysparm_templateid');

        var parentid = this.getParameter('sysparm_legal_id');

        var table = this.getParameter('sysparm_legal_table');

       

        // Get template record selected

        var ltt = new GlideRecord('sn_sm_legal_task_template');

        ltt.get(templateid);

       

        var Legal = new GlideRecord('sn_sm_legal_request');

        legal.get(parentid);

       

        // Create sub task with data from the templatea

        var lt = new GlideRecord('sn_sm_legal_task');

        Legaltask.initialize();

        Legaltask.parent = parentid;

        Legaltask.short_description = LegaltaskTemplate.u_short_description;

        Legaltask.description = LegaltaskTemplate.u_description;

        Legaltask.u_type = LegaltaskTemplate.u_task_type;

        //Legal Request fields to Legal Task

        //lt.u_field = legal.u_field;

        //lt.u_field = legal.u_field;

        //lt.u_field = legal.u_field;

        var taskid = Legaltask.insert();

       

        // Set state of parent Legal Request to that specified in the task template

        this._setLegalState(parentid, ltt.u_state);

        return taskid;

        },

       

        _setLegalState: function(parentid, state) {

        var legal = new GlideRecord('sn_sm_legal_request');

        legal.get(parentid);

        legal.state = state;

        legal.update();

        }

      }

       

      When I click on the Add Legal Task Icon this is what I see

       

       

       

      Sorry for the long note, just wanted to give as much information as possible.

      Blaze Llanos

      Semper Fi

      PS - Please mark Helpful, Like, or Correct Answer if applicable.