link request task to change request

osvaldo2
Kilo Contributor

Has anyone been able to link a request tasks to a change request similar as showing in this steps. Link changes to a project task   I am able to see it creates a change from the task but I cant get the task to show up linked on the change request?

1 ACCEPTED SOLUTION

Thats great.. You found it. But it is referencing the Catalog Task instead of Change Request or Task table, while you in the script you are trying to store the change request. Something is wrong with the way it is implemented.



You   also need to correct this line in the script.


link.eislinked_task = changeRequest.insert();



It should be


link.u_eis_linked_task = changeRequest.insert();



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

29 REPLIES 29

I must be doing something wrong then, I would think it would be the short description:



change request fields


find_real_file.png




task fields


find_real_file.png


Can you post the code, how you are creating the Change Request. You should add a reference to the task or RITM on Change while creating the Change.



Please mark this response as correct or helpful if it assisted you with your question.

I have the following code on the request task:



On table: sc_task


UI Action: Create Change and link from EIS Request




***************************


createChange();


function createChange() {
    current.link = true;
    current.rollup = true;
    current.update();
    action.setReturnURL(current);
    var link = new GlideRecord("u_eis_task_link");
    link.initialize();
    link.parent = current.sys_id;

    var changeRequest = new GlideRecord("change_request");
    changeRequest.short_description = current.short_description;
    link.eislinked_task = changeRequest.insert();
    new EISTaskLinkUtils().copyChangeInfoToLink(link, changeRequest);
    link.insert();
   
    gs.addInfoMessage(gs.getMessage("Change Request {0} created", changeRequest.number));
    action.setRedirectURL(changeRequest);
}


***********************************


The code above is to produce the link below on the task


find_real_file.png



The following scrip include:



EISTaskLinkUtils




***********************************



var EISTaskLinkUtils = Class.create();
EISTaskLinkUtils.prototype = {
      initialize: function() {
      },



/**
      * Copies all the required data from the Change record to u_eis_task_link record
      * 1. If the time is not in the schedule then the first time in the schedule after time
* 2. If the time is in the schedule then the first time in the schedule for the next day
*
* Usage
*     var EnhancementTaskManagerUtil = new EnhancementTaskManagerUtil();
      *     var calculatedStartDate = EnhancementTaskManagerUtil.copyChangeInfoToLink(link, change);
*
* @method copyChangeInfoToLink
* @param {object} link : destination record from the table "u_eis_task_link" to be filled by this function
* @param {string} change : source record from the table "change" to be filled by this function
    **/    
copyChangeInfoToLink: function(link, change) {  
  link.short_description = change.short_description;
  link.description = change.description;
  link.state = change.state;
  link.active = change.active;
  link.time_constraint = "start_on";
 
 
  if (!change.start_date.nil() && !change.end_date.nil()) {
    link.start_date = change.start_date;
    link.end_date = change.end_date;
  } else {
    var now_time = GlideSystemDateUtil.nowDateTime();
    link.start_date = now_time;
    link.time_constraint = "asap";
    link.duration = "01 00:00:00";
  }
 
  link.work_start = change.work_start;
  link.work_end = change.work_end;
  link.approval = change.approval;
},




      type: 'EISTaskLinkUtils'
};



**********************************************


UI page:Link an existing Change Request to the Task



********************************************


HTML Part:




<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<form action="ui_page_process.do">
  <input type="hidden" name="name" value="link_existing_change_to_task"/>
  <input type="hidden" id="cancelled" name="cancelled" value="false"/>


  <g:evaluate>
        var parent_task = '${sysparm_sysID}';
        var table_name = "change_request";
  </g:evaluate>
<br/>
<span> Use the lookup icon to display records from the change request table</span>


    <table>
          <tr>
                <td nowrap="true"> ${gs.getMessage('Change Request')}: </td>
                      <td colspan="4">
                            <g:ui_reference name="document_key" id="document_key" table="${table_name}"/>
                      </td>
          </tr>
         
          <tr>


          </tr>
          <tr id="dialogbuttons">
                  <td colspan="2" align="right">
                        <g2:dialog_button onclick="return onSubmit();" name="ok_button" id="ok_button">${gs.getMessage('OK')}</g2:dialog_button>
                        <g2:dialog_button onclick="return onCancel();" name="cancel_button" id="cancel_button">${gs.getMessage('Cancel')}</g2:dialog_button>
                  </td>
          </tr>
    </table>
    <input type="hidden" name="parent_task" id="parent_task" value="${sysparm_sysID}"/>
</form>
</j:jelly>





Client Script Part:




********************************************


function setupReference() {
    var tn = gel('table_name').value;
    gel('document_keyTABLE').value = tn;
}


function setName() {
  var task = gel('sys_original.document_key');
  if (task)
        $("document_name").value = task.value;
}


function onCancel() {
  var c = gel('cancelled');
  c.value = "true";
  GlideDialogWindow.get().destroy();
  return false;
}


function onSubmit() {
    var task = gel('document_key').value;
   
    if (task == "") {
    alert(getMessage("Enter a valid change request to link"));
    return false;
    }
    return true;
}



********************************************






********************************************


procession script part:




if (cancelled == "false") {
    var parent = new GlideRecord("sc_task");
    parent.get(parent_task);
if (parent.link != true) {
      parent.link = true;
      parent.update();
}

var change = new GlideRecord("change_request");
change.get(document_key);

    var link = new GlideRecord("u_eis_task_link");
link.addQuery("parent", parent_task);
link.addQuery("eislinked_task", document_key);
link.query();
if (!link.hasNext()) {
  link = new GlideRecord("u_eis_task_link");
  link.initialize();
  link.eislinked_task = document_key;
  link.parent = parent_task;
        var sys_id = link.insert();
  link.get(sys_id);
  new EISTaskLinkUtils().copyChangeInfoToLink(link, change);
  link.update();
} else
  gs.addErrorMessage(gs.getMessage("A link to the selected Change already exists"));
   
    redirectTo();
}


function redirectTo() {
    var urlOnStack = parent.sys_class_name + ".do?sys_id="
    + parent_task;
    response.sendRedirect(urlOnStack);
}




********************************************




I might be doing this wrong but that's the code I'm using for this. Any help is much appreciated.



Thanks,



Osvaldo


So you have it all in your script.



    var link = new GlideRecord("u_eis_task_link");


    link.initialize();


  link.parent = current.sys_id;



    var changeRequest = new GlideRecord("change_request");


    changeRequest.short_description = current.short_description;


    link.eislinked_task = changeRequest.insert();


    new EISTaskLinkUtils().copyChangeInfoToLink(link, changeRequest);


    link.insert();



In your change request form layout, expand the reference field eislinked_task. The eislinked_task will have a parent field. Move it to the right bucket and you will be able to see the task number.



Please mark this response as correct or helpful if it assisted you with your question.

when I open the change form layout, I see the following:



find_real_file.png



If I add that to the form, I get the following:



find_real_file.png


The linked task should be showing up further in the bottom under the page



find_real_file.png