Hide Activity Fields

IT MonkeyIT Monkey O.G.
edited May 2016 in Cireson Uploads
Provides the code to hide fields on activities. This is dynamic and you can add additional field names as desired.

*Currently only works for Service Requests but can be easily adapted to support Change Requests*

//start hide activity fields
app.custom.formTasks.add('ServiceRequest', null, function(formObj, viewModel){  
      formObj.boundReady(function () {
            var targetFields = [
                  "Area",
                  "Priority",
                  "Stage",
                  "Scheduled Start",
                  "Scheduled End",
                  "Impacted Configuration Items"
            ]
            
            fn_HideActivityFields(targetFields);
      });
});
      
function fn_HideActivityFields (fields) {
    $("div.panel-heading:contains('Activities')").parent().on("mouseenter", function (){
        console.log("I'm hiding fields!", fields);
        for(var i=0; i < fields.length; i++){
                var label = fields[i];
                var item = $("div.activity-item-form").find("label span:contains(" + label + ")");
                $(item).each(function () {
                    var ctrl = $(this).parents("div")[2];
                    $(ctrl).hide();
                });
        }  
    });
}
//END hide activity fields

Download the attached .zip file below.

Comments

  • Xiaoqian_LiXiaoqian_Li IT Monkey ✭

    We won't be able to hide MA "Actual Start Date" and "Actual End Date" ("Actual Start"/"Actual End") since it is not shown on SCSM console. And found out that Data-control-bind="ActualStartDate" data-control-to="ScheduleEndDate". Please help. Thank you.

  • PIERRE-LOUIS_DURRISPIERRE-LOUIS_DURRIS Adept IT Monkey ✭✭
    Just for information, this work only for english language as we are working on description and not field.
    I had to fill the exact description in french to be able to hide these fields. You need to hide field for each language.
    I have been able to fill Actual Start Date and Actual End Date with the full french description.
    The check to hide field seems also to be case sensitive.
  • Xiaoqian_LiXiaoqian_Li IT Monkey ✭
    Thank you for the clue. It is case sensitive. This works after using "Actual start" and "Actual end".
  • Leigh_KildayLeigh_Kilday Advanced IT Monkey ✭✭✭

    We would like to hide Line Manager Should Review. I've tried a few combinations for this field and haven't been successful so far. Has anybody got a solution for this?

  • Thomas_StrombergThomas_Stromberg Adept IT Monkey ✭✭
    Have anyone found a way to make this work if you click on a MA for example direct in the view? If you do that the hide fields does not work. When i click on an activity direct from my workitems i get the link /ServiceRequest/Edit/SR123897?activityId=MA123899&tab=activity

    And if i click into the SR123897 and then click on activities the link is just. /ServiceRequest/Edit/SR123897#

  • We would like to hide Line Manager Should Review. I've tried a few combinations for this field and haven't been successful so far. Has anybody got a solution for this?

    I will say an unsupported way would be to comment out that section in the HTML [C:\inetpub\CiresonPortal\Scripts\app\templates\activity].

    I suspect you would have to do that every time it updates, and test, test.
  • Eugen_MuellerEugen_Mueller IT Monkey ✭
    Great!!!!!!!
  • Geoff_RossGeoff_Ross Super IT Monkey ✭✭✭✭✭
    @Leigh_Kilday

    Simple add "Line Manager Should Review" to the list of fields to hide.

    Geoff
  • I have actually included the hiding of the Approve and Reject All buttons.
    Line of code is from this discussion here: https://community.cireson.com/discussion/comment/3746#Comment_3746

    I changed the function like this:


    //Hide activity Fields and Buttons Function function fn_HideActivityFields (fields) {    $("div.panel-heading:contains('Activities')").parent().on("mouseenter", function (){        console.log("I'm hiding fields!", fields);        for(var i=0; i < fields.length; i++){                var label = fields[i];                var item = $("div.activity-item-form").find("label span:contains(" + label + ")");                $(item).each(function () {                    var ctrl = $(this).parents("div")[2];                    $(ctrl).hide();                });        }  		//Hide the Approve an Reject All		console.log("I'm hiding CR Approve and Reject All buttons!");		$('div[class=reviewer-controls]').hide()		    });}//END hide activity fields
  • Geoff_RossGeoff_Ross Super IT Monkey ✭✭✭✭✭
    Makes sense to bundle into one. Stay tuned for a new solution I will post tonight to help with Activities.
  • Aaron_BoockAaron_Boock Adept IT Monkey ✭✭
    How can I disable the fields, or a specific field, rather than hide?  Similar to disabled:true in one of the json work item templates
  • Jonathan_BolesJonathan_Boles Ninja IT Monkey ✭✭✭✭
    Makes sense to bundle into one. Stay tuned for a new solution I will post tonight to help with Activities.
    Hi @Geoff_Ross, is there a solution for hiding the Approval All/Reject All that leaves the regular approve/reject buttons in place?
  • Geoff_RossGeoff_Ross Super IT Monkey ✭✭✭✭✭
    @Jonathan_Boles
    See my comment (Marked as Answer) on this thread

    https://community.cireson.com/discussion/comment/3746#Comment_3746

    Is that what you need?
    Geoff
  • Geoff_RossGeoff_Ross Super IT Monkey ✭✭✭✭✭
    @Aaron_Boock Just seen your question above about disabling instead of hiding.

    Check out https://community.cireson.com/discussion/1538/can-we-set-activity-fields-as-read-only-for-approvers#Item_1

    Geoff
  • A different approach - hide runbook activities and disable the toggle on manual activities.  Means that the end user can only drill into Review Activities:

    $(document).ready(function(){
     $( "div.activity-item-header[data-activity-id^=RB]" ).hide();
     $( "div.activity-item-header[data-activity-id^=MA]" ).next( "div.activity-item-body" ).attr( "data-for-action", "" );
    });

    (Bear in mind, I still need to target the above code to run only for users without analyst rights...)

  • ...continued from previous post...

    ...except the js code directly above doesn't seem to have the desired effect when added to custom.js, it only seems to work when running in the debug console (F12).

    I can see that the function is being executed but my current theory is that something else is coming along afterwards and trouncing any of the function's changes.

    Am I making some noob mistake here?

  • I have adjusted the Script example in the above with this code just after hiding the Approve and Reject All buttons:

    //start hide SR activity fieldsapp.custom.formTasks.add('ServiceRequest', null, function(formObj, viewModel){        formObj.boundReady(function () {            var targetFields = [                  "Area",                  "Priority",                  "Stage",                  "Scheduled Start",                  "Scheduled End",                  "Impacted Configuration Items",				  "Line Manager Should Review"            ]                        fn_HideActivityFields(targetFields);      });}); //start hide CR activity fieldsapp.custom.formTasks.add('ChangeRequest', null, function(formObj, viewModel){        formObj.boundReady(function () {            var targetFields = [                  "Area",                  "Priority",                  "Stage",                  "Scheduled Start",                  "Scheduled End",                  "Impacted Configuration Items",				  "Line Manager Should Review"            ]                        fn_HideActivityFields(targetFields);      });});
    //Hide activity Fields and Buttons Function function fn_HideActivityFields (fields) {    $("div.panel-heading:contains('Activities')").parent().on("mouseenter", function (){        console.log("I'm hiding fields!", fields);        for(var i=0; i < fields.length; i++){                var label = fields[i];                var item = $("div.activity-item-form").find("label span:contains(" + label + ")");                $(item).each(function () {                    var ctrl = $(this).parents("div")[2];                    $(ctrl).hide();                });        }   //Hide the Approve an Reject All console.log("I'm hiding RA Approve and Reject All buttons!"); $('div[class=reviewer-controls]').hide() //Hide Runbook Activities for End Users if (session.user.Analyst !== 1) { console.log("I'm hiding Activites for End Users!"); $( "div.activity-item-header[data-activity-id^=RB]" ).hide(); $( "div.activity-item-header[data-activity-id^=MA]" ).next( "div.activity-item-body" ).attr( "data-for-action", "" ); }     });}//END hide activity fields
    As always the code gets jacked up when pasting, so adding the code as attachment as well.
  • Just for information, this work only for english language as we are working on description and not field.
    I had to fill the exact description in french to be able to hide these fields. You need to hide field for each language.
    I have been able to fill Actual Start Date and Actual End Date with the full french description.
    The check to hide field seems also to be case sensitive.
    Been trying to hide this in other languages than English, without luck. Do i use the name of the field as it is presented in the portal? Or do i have to find this description you are mentioning some other place? If so, where do i find it?
  • Nicholas_VelichNicholas_Velich Advanced IT Monkey ✭✭✭
     Hi Tom,

    Localization can be done in the Portal by using the localization keys in the following format:

    localization.NameOfKey

    The names of the keys can be found by admins in the Localization section of the Portal.

    For this exact customization, I have attached a fully localized example which will work in every language. Additionally, the attached example uses a new-and-improved method of triggering the customization. Rather than triggering on a MouseEnter event, it is triggering using a mutation observer. The mutation observer method is a more effective way of applying changes to a page whose content is not immediately available. 

    Give the attached a shot, and let me know how it goes or if you have any questions!

    Thanks,
    Nick
  • Adrian_ProbstAdrian_Probst IT Monkey ✭
     Hi Tom,

    Localization can be done in the Portal by using the localization keys in the following format:

    localization.NameOfKey

    The names of the keys can be found by admins in the Localization section of the Portal.

    For this exact customization, I have attached a fully localized example which will work in every language. Additionally, the attached example uses a new-and-improved method of triggering the customization. Rather than triggering on a MouseEnter event, it is triggering using a mutation observer. The mutation observer method is a more effective way of applying changes to a page whose content is not immediately available. 

    Give the attached a shot, and let me know how it goes or if you have any questions!

    Thanks,
    Nick
    Hi Nick

    The attached code works perfectly, thanks!

    One question:
    When I put in the field "Approval Threshold (%)" (Key Name: ApprovalThreshold%) into the target fields, it doesn't work - and not only for this field, if this is added all other fields are shown again.

    Is there maybe a problem with the '%' character?

    Thanks for your help,
    Adrian
  • Geoff_RossGeoff_Ross Super IT Monkey ✭✭✭✭✭
    Hi Adrian,

    I suspect it is an issue with the %. However, the actual property name for that field is 'ApprovalPercentage'. Try that.

    Geoff
  •  Hi Tom,

    Localization can be done in the Portal by using the localization keys in the following format:

    localization.NameOfKey

    The names of the keys can be found by admins in the Localization section of the Portal.

    For this exact customization, I have attached a fully localized example which will work in every language. Additionally, the attached example uses a new-and-improved method of triggering the customization. Rather than triggering on a MouseEnter event, it is triggering using a mutation observer. The mutation observer method is a more effective way of applying changes to a page whose content is not immediately available. 

    Give the attached a shot, and let me know how it goes or if you have any questions!

    Thanks,
    Nick
    Hi Nick,

    That worked great on all languages!
    Added Scheduled Start and End Date and it worked perfectly.
    Thanks!

    TVN
  • Adrian_ProbstAdrian_Probst IT Monkey ✭
    Hi Adrian,

    I suspect it is an issue with the %. However, the actual property name for that field is 'ApprovalPercentage'. Try that.

    Geoff
    Hi Geoff

    The 'ApprovalPercentage' is the wrong one.


    Adrian
  • Geoff_RossGeoff_Ross Super IT Monkey ✭✭✭✭✭
    Hi Adrian,

    Sorry, I've looked at the code and its actually looking for a element where the label contains the provided text. Therefore, try just 'Approval Threshold'

    Geoff
  • Adrian_ProbstAdrian_Probst IT Monkey ✭
    Hi Geoff

    That's what I tried first ;)
    But I think on the RA form is the "ApprovalThreshold%" used. Only for this Key is the translation correct.
    If there is the "ApprovalThreshold" used, I should see "_Genehmigungsschwellenwert (%)" in the portal:


    Adrian
  • Nicholas_VelichNicholas_Velich Advanced IT Monkey ✭✭✭
    Hi Adrian,

    The "ApprovalThreshold%" key is indeed being used on the RA form. It is an odd key in that it has a non-alphanumeric character in the key, which JavaScript doesn't like. I don't know of a way to directly escape that character using the localization.NameOfKey approach, but since the "(%)" part is consistent across most languages, and the "ApprovalThreshold" key is likely similar, you could do this:

    var targetFields = [
            localization.Area,
            localization.Priority,
            localization.Stage,
            localization.ImpactedConfigurationIte,
            localization.LineManagerShouldReview,
            localization.ApprovalThreshold + "(%)"
    ]

    As Geoff mentioned, this code is not looking for an exact match either, so as long as you have a portion of the label present, it will work.

    Thanks,
    Nick
  • Adrian_ProbstAdrian_Probst IT Monkey ✭
    Hi Nick

    I found the problem:
    The "localization.ApprovalThreshold" key didn't work because there is a completely other Display String in German. I change this in the settings to the same string as the "localization.ApprovalThreshold%".
    Now it works perfectly!

    Thanks for your help!
    Adrian
  • Tim_ShackletonTim_Shackleton IT Monkey ✭
    This is a great script!  How would I target properties just in MAs to hide rather than blanket all child activities?
  • Tim_ShackletonTim_Shackleton IT Monkey ✭
     Hi Tom,

    Localization can be done in the Portal by using the localization keys in the following format:

    localization.NameOfKey

    The names of the keys can be found by admins in the Localization section of the Portal.

    For this exact customization, I have attached a fully localized example which will work in every language. Additionally, the attached example uses a new-and-improved method of triggering the customization. Rather than triggering on a MouseEnter event, it is triggering using a mutation observer. The mutation observer method is a more effective way of applying changes to a page whose content is not immediately available. 

    Give the attached a shot, and let me know how it goes or if you have any questions!

    Thanks,
    Nick

    This is great, but to get it working in my environment (7.4) I had to swap

    loadScript("/CustomSpace/HideActivityFields/HideActivityFields.js");

    for

    $.getScript("/CustomSpace/HideActivityFields/HideActivityFields.js");

    in the custom.css file.
  • Brad_HayesBrad_Hayes IT Monkey ✭

    I also found that hiding all Parallel Activities and Sequential Activities cleaned up the activity listing
    As we only use these activities to order the tasks and they are never assigned there was no issue in hiding them...

    /**************************************************************/
    /*** Hide all Parallel and Sequential activities for all users ***/
    /**************************************************************/
    console.log("Hiding Parallel Activities and Sequential Activities");
      $( "div.activity-item-header[data-activity-id^=PA]" ).hide();
      $( "div.activity-item-header[data-activity-id^=SA]" ).hide();

Sign In or Register to comment.