Home Analyst Portal

Display of the standard task of Cireson in the closed WI

Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭

Hi guys!

I need to display in the closed WI the standard task of Cireson - "Print".

Help, please!

Best Answer

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭
    Answer ✓

    Hi,

    the timinig can be a little bit difficult, but the following approach might help to use Cireson predefined tasks on closed WI:

    $(document).ready(function ()
     {
     var pathArray = window.location.href;
     var allowedLinks = ['ServiceRequest','Incident', 'Change', 'View'],
     length = allowedLinks.length;
      while(length--) {
         if (pathArray.indexOf(allowedLinks[length])!=-1)
          {  // taken from wimain.js 
        require.config({
         waitSeconds: 0,
         urlArgs: "v=" + session.staticFileVersion,
         baseUrl: "/Scripts/",
         paths: {text: "require/text"},
         shim: {}
        });
        
        if (typeof pageForm !='undefined')
        { 
        if (pageForm.viewModel.Status.Id == "f228d50b-2b5a-010f-b1a4-5c7d95703a9b") // Status "closed Change"
        {
          setTimeout(function () { //taskspane not loaded - wait some time ... ;)
         var ulElement=$('.task-panel');
         ulElement.append("<h2>Tasks</h2><ul class='taskmenu'></ul>");   

         require(["forms/tasks/print/controller"], function (prController) {
          task={"Label": "My Print", "Task": "prController", "Configs" : {}};
          eval("var _obj = " + task.Task + ";");
          _obj.build(pageForm, task, function (view) {             
            ulElement=$('.taskmenu');
            ulElement.append(view);              
           });  
          }); 

        require(["forms/tasks/sendEmail/controller"], function (emailController) {
          task={"Label": "My eMail", "Task": "emailController", "Configs" : {}};
          eval("var _obj = " + task.Task + ";");
          _obj.build(pageForm, task, function (view) {             
            ulElement=$('.taskmenu');
            ulElement.append(view);              
           });  
          });       
          }, 2000);
          };
        };    
      }     
     }

Answers

  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    edited January 2017
    There is a thread about this (mainly consisting of me talking to myself :)): https://community.cireson.com/discussion/comment/3048#Comment_3048

    However, I have since updated the code a bit:
        var&nbsp;mainPageNode&nbsp;=&nbsp;document.getElementById('main_wrapper');<br> &nbsp;<br>    //&nbsp;create&nbsp;an&nbsp;observer&nbsp;instance
        var&nbsp;observer&nbsp;=&nbsp;new&nbsp;MutationObserver(function&nbsp;(mutations)&nbsp;{<br>      //The&nbsp;page&nbsp;changed.&nbsp;See&nbsp;if&nbsp;our&nbsp;title&nbsp;exists.
          var&nbsp;titleElement&nbsp;=&nbsp;$(".page_title");
    <br>      //An&nbsp;element&nbsp;with&nbsp;class&nbsp;of&nbsp;page_title&nbsp;exists,&nbsp;AND&nbsp;REQUIREJS&nbsp;HAS&nbsp;LOADED.
          if&nbsp;(titleElement.length&nbsp;>&nbsp;0&nbsp;&&&nbsp;window.require)&nbsp;{	
            if&nbsp;($("ul.taskmenu").length&nbsp;<&nbsp;1)&nbsp;{
            //&nbsp;Add&nbsp;the&nbsp;task&nbsp;panel&nbsp;back&nbsp;into&nbsp;the&nbsp;form
            $(".task-panel").append("<h2>Tasks</h2><ul class='taskmenu'></ul>");
    <br>        //&nbsp;Add&nbsp;the&nbsp;desired&nbsp;task&nbsp;functions&nbsp;back&nbsp;to&nbsp;the&nbsp;list<br>        $(".taskmenu").append("<li&nbsp;class='link'&nbsp;onclick='print();'>Print</li>");
            $(".taskmenu").append("<li&nbsp;class='link'&nbsp;onclick='func2();'>Task2</li>");
            $(".taskmenu").append("<li&nbsp;class='link'&nbsp;onclick='func3();'>Task3</li>");
            $(".taskmenu").append("<li&nbsp;class='link'&nbsp;onclick='func4();'>Task4</li>");
          }<br>    <br>      //We&nbsp;are&nbsp;done&nbsp;observing.
          observer.disconnect();<br>&nbsp;   });<br>  <br>    //&nbsp;configure&nbsp;the&nbsp;observer&nbsp;and&nbsp;start&nbsp;the&nbsp;instance.
        var&nbsp;observerConfig&nbsp;=&nbsp;{&nbsp;attributes:&nbsp;true,&nbsp;childList:&nbsp;true,&nbsp;subtree:&nbsp;true,&nbsp;characterData:&nbsp;true&nbsp;};
        observer.observe(mainPageNode,&nbsp;observerConfig); <br>  }<br>});<br></code><code>$(document).ready(function() {<br> &nbsp;if&nbsp;(pageForm.viewModel.Status.Name&nbsp;==&nbsp;"Closed")&nbsp;{<br>
    "func2()", "func3()", and "func4()" are just placeholders, of course, but I added the function for printing at the top for you.

    Note that for me, this is running inside of a script that is only loaded if the current page is a CR form, so if you are just dropping this into your custom.js file, you may want to wrap it in another IF statement that checks to see that the current page is one of the work item forms.

  • Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭

    Thanks, but this code doesn't allow to use the built-in tasks Cireson such as:
    - Print: inetpub\CiresonPortal\Scripts\forms\tasks\print\
    - sendEmail: inetpub\CiresonPortal\Scripts\forms\tasks\sendEmail\
    - etc.

    I already saw your decision, but it didn't suit me. :( 

  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    Print is the same, but you are correct about the sendEmail task.  I would have responded differently if that was also mentioned.

    This code will get the task panel to appear so that you can attach tasks, but someone from Cireson will have to step in to explain how to add their OOB tasks.  I have not been successful in my attempts.

    If someone from Cireson would be so kind as to either convert my original request (which is in the feature request folder but the voting buttons never appeared) or this one into a feature request, perhaps we can get enough votes for Cireson to make this work OOB (which I prefer to using this code).
  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    @Tom_Hendricks
    Converted your original post and upvoted.
  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    Thanks, @Geoff_Ross!
  • Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭
    Thanks!
    I voted in a request: https://community.cireson.com/discussion/comment/3048#Comment_3048
    I need extremely it!
  • Vladimir_BudyakVladimir_Budyak Customer IT Monkey ✭
    Hello!
    Is there any new information?
  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭
    Answer ✓

    Hi,

    the timinig can be a little bit difficult, but the following approach might help to use Cireson predefined tasks on closed WI:

    $(document).ready(function ()
     {
     var pathArray = window.location.href;
     var allowedLinks = ['ServiceRequest','Incident', 'Change', 'View'],
     length = allowedLinks.length;
      while(length--) {
         if (pathArray.indexOf(allowedLinks[length])!=-1)
          {  // taken from wimain.js 
        require.config({
         waitSeconds: 0,
         urlArgs: "v=" + session.staticFileVersion,
         baseUrl: "/Scripts/",
         paths: {text: "require/text"},
         shim: {}
        });
        
        if (typeof pageForm !='undefined')
        { 
        if (pageForm.viewModel.Status.Id == "f228d50b-2b5a-010f-b1a4-5c7d95703a9b") // Status "closed Change"
        {
          setTimeout(function () { //taskspane not loaded - wait some time ... ;)
         var ulElement=$('.task-panel');
         ulElement.append("<h2>Tasks</h2><ul class='taskmenu'></ul>");   

         require(["forms/tasks/print/controller"], function (prController) {
          task={"Label": "My Print", "Task": "prController", "Configs" : {}};
          eval("var _obj = " + task.Task + ";");
          _obj.build(pageForm, task, function (view) {             
            ulElement=$('.taskmenu');
            ulElement.append(view);              
           });  
          }); 

        require(["forms/tasks/sendEmail/controller"], function (emailController) {
          task={"Label": "My eMail", "Task": "emailController", "Configs" : {}};
          eval("var _obj = " + task.Task + ";");
          _obj.build(pageForm, task, function (view) {             
            ulElement=$('.taskmenu');
            ulElement.append(view);              
           });  
          });       
          }, 2000);
          };
        };    
      }     
     }

Sign In or Register to comment.