Home Analyst Portal

Disable Title and description editing

Gerhard_GoossensGerhard_Goossens Customer Advanced IT Monkey ✭✭✭
Good day everyone,

I have been playing around with forms and came across a strange issue.

I want to disable the editing of the title and description fields in the IR and SR forms. I have done this by copying the incident.js to CustomScripts and changing the property to read-only. This works as expected...

The problem I have is that when I create a new Incident via the drawer -> New -> Work Item -> Incident -> From Template the title and description cant be edited and thus the Incident cant be logged.

The reason I want to do it via the templates is that I cant create templates for every possible scenario and the quick create is not as quick as the name implies ;-) The analysts have to fill in all the fields in the quick create and it is time consuming.

If someone can suggest an alternate way to do this it will be much appreciated.

Regards
Gerhard

Best Answers

  • Gerhard_GoossensGerhard_Goossens Customer Advanced IT Monkey ✭✭✭
    Answer ✓
    Ok, got it figured out ;-)

    app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
        //Form Ready
        formObj.boundReady(function () {
            // Get new work item status
            var newWorkItem = pageForm.newWI.toString();
            // Check if it is a new work item
            if ( newWorkItem == "false") {
                // Assign properties to disable
                var disableRequestedWI = document.getElementsByName('RequestedWorkItem')[0];
                var disableTitle = document.getElementsByName('Title')[0];
                var disableDescription = document.getElementsByName('Description')[0];
                // Disable properties
                disableRequestedWI.setAttribute("disabled", "true");
                disableTitle.setAttribute("disabled", "true");
                disableDescription.setAttribute("disabled", "true");
            };
        });
    });
    
    So this will disable the textboxes for the user who requested the WorkItem. the Title and Description. If the work item is not new. ie created from the drawer New -> Work Item ...


Answers

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭

    Hi,

    maybe an alternate approach could be (instead of modifying the incident.js):

    var OptionsDictionary= {'Title': '', 'Description' : ''};  // definition of "object labels" which should be disabled
     
     qcontainer=$('.form-group'); // 
       
       for (i = 0; i < qcontainer.length; i++) {   
       prompt=qcontainer[i].children[0].htmlFor
       
       if (prompt in OptionsDictionary) // true if "key" exist in object
       {
         qcontainer[i].children[1].disabled=true;
        qcontainer[i].children[2].disabled=true; 
       }
      }

    you could check the html title to see, if the workitem is "new" or not and if you are applying this on the correct workitem type ...

    hope this helps

    Roland


  • Gerhard_GoossensGerhard_Goossens Customer Advanced IT Monkey ✭✭✭
    I cant get it to work. If I check the elements/properties in the console I can disable the Title, but it does not want to work through JS.

    I suspect that the function gets overwritten by the incident.js after load

    function disableTitle() {
     if (pageForm.newWI=false) {
         var setTitle = document.getElementsByName('Title')[0];
         setTitle.setAttribute("readonly", "true");
        }
     }

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭

    Hi,

    for testing I have it implemented in a function like that:

    $(document).ready(function ()
     {
     setTimeout(function () { // wait some time ... ;)
     
      var OptionsDictionary= {'Title': '', 'Description' : ''};  // definition of "labels for objects" which should be disabled
      
       qcontainer=$('.form-group'); //
        
        
         for (i = 0; i < qcontainer.length; i++) {    
         prompt=qcontainer[i].children[0].htmlFor   
         if (prompt in OptionsDictionary) // true if "key" exist in object
         {
          qcontainer[i].children[1].disabled=true;
          qcontainer[i].children[2].disabled=true; 
         }
        }       

          
     }, 2000);
     });

  • Gerhard_GoossensGerhard_Goossens Customer Advanced IT Monkey ✭✭✭

    Hi,

    for testing I have it implemented in a function like that:

    $(document).ready(function ()
     {
     setTimeout(function () { // wait some time ... ;)
     
      var OptionsDictionary= {'Title': '', 'Description' : ''};  // definition of "labels for objects" which should be disabled
      
       qcontainer=$('.form-group'); //
        
        
         for (i = 0; i < qcontainer.length; i++) {    
         prompt=qcontainer[i].children[0].htmlFor   
         if (prompt in OptionsDictionary) // true if "key" exist in object
         {
          qcontainer[i].children[1].disabled=true;
          qcontainer[i].children[2].disabled=true; 
         }
        }       

          
     }, 2000);
     });

    Thanks for the help, although this disables the Title and Description, it also disables them for when you create a work item via a template from the drawer. 

    I'm currently trying to figure out how to check for pageForm.newWI=false  and only then disable the Title, Description and affectedUser.
  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭

    Hi,

    $(document).ready(function ()
     {
     if (pageForm.newWI==false)
     {
      setTimeout(function () { // wait some time ... ;)
     
       var OptionsDictionary= {'Title': '', 'Description' : ''};  // definition of "labels for objects" which should be disabled
       
        qcontainer=$('.form-group'); //
         
         
          for (i = 0; i < qcontainer.length; i++) {    
          prompt=qcontainer[i].children[0].htmlFor   
          if (prompt in OptionsDictionary) // true if "key" exist in object
          {
           qcontainer[i].children[1].disabled=true;
           qcontainer[i].children[2].disabled=true; 
          }
         }       

           
      }, 2000);
     }
     });

    regards


  • Gerhard_GoossensGerhard_Goossens Customer Advanced IT Monkey ✭✭✭
    Answer ✓
    Ok, got it figured out ;-)

    app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
        //Form Ready
        formObj.boundReady(function () {
            // Get new work item status
            var newWorkItem = pageForm.newWI.toString();
            // Check if it is a new work item
            if ( newWorkItem == "false") {
                // Assign properties to disable
                var disableRequestedWI = document.getElementsByName('RequestedWorkItem')[0];
                var disableTitle = document.getElementsByName('Title')[0];
                var disableDescription = document.getElementsByName('Description')[0];
                // Disable properties
                disableRequestedWI.setAttribute("disabled", "true");
                disableTitle.setAttribute("disabled", "true");
                disableDescription.setAttribute("disabled", "true");
            };
        });
    });
    
    So this will disable the textboxes for the user who requested the WorkItem. the Title and Description. If the work item is not new. ie created from the drawer New -> Work Item ...


Sign In or Register to comment.