Home Self-Service Portal - Community

Disable enduser comments if IR/SR are closed

Hi all. Is there a way to disable enduser comments insertion, if an incident or a service request has been closed?
I've tried to do this by using "app.custom.formTasks.add" technique, but I wasn't able to get the desired behavior :/

Thanks a lot! :)

Comments

  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    That is because those methods do not run on closed tickets.  custom.js still runs, however, so you could achieve it by looking at the URL of the window to see what kind of page is loaded and if it is a ticket, check pageForm.viewModel.Status.Name for "Closed" then disable the field.

    There have been several feature requests in the past to allow code to run on Closed tickets, but I do not see much traction there, unfortunately.
  • Alberto_FumagalliAlberto_Fumagalli Customer IT Monkey ✭
    By following you suggestions, I put this code in my custom.js file:

    $(document).ready(function (formObj) {
        var pageLink = window.location.toString();
        if ((pageLink.indexOf("/Incident/Edit/IR") !== -1)  || (pageLink.indexOf("/ServiceRequest/Edit/SR") !== -1)){
            if(pageForm.viewModel.Status.Id == "bd0ae7c4-3315-2eb3-7933-82dfc482dbaf" || pageForm.viewModel.Status.Id == "c7b65747-f99e-c108-1e17-3c1062138fc4"){
                $('[data-bind="click: addComment"]').hide();
                console.log("condition found");
            }
        }
    });


    The page still doesn't disable/hide the addComment button, but...If I use browser debugger, I perfectly see the message written on the console and...If I manually type $('[data-bind="click: addComment"]').hide() in the debug console, then the button disappears...

    What is wrong with the above code?
    Thanks! :)








  • Tom_HendricksTom_Hendricks Customer Super IT Monkey ✭✭✭✭✭
    I would bet that your code is running before the page is fully rendered.  Document.ready() occurs long before boundReady would have.  That is why it works when you type it in the console--the form is fully rendered at that point.

    Most of us use a mutation observer to determine when the form is finished rendering, in situations like this.  You will see it in much of the custom code in the Cireson or Community upload sections of the site.

    Try something like this:

    $(document).ready(function () {
    	if (pageForm.viewModel.Status.Name === "Closed") {
    		var mainPageNode = document.getElementById('main_wrapper');
     
    		// create an observer instance
    		var observer = new MutationObserver(function (mutations) {
    			//The page changed. See if our title exists. If it does, then proceed.
    			var titleElement = $(".page_title"); //The title always exists when the form is rendered.
    
    			//An element with class of page_title exists.
    			if (titleElement.length > 0) {
    				//We are done observing.  Do not keep running this!
    				observer.disconnect();

    // Your code
    $('[data-bind="click: addComment"]').hide();
    console.log("condition found");
    }
    });

    // configure the observer and start the instance. var observerConfig = { attributes: true, childList: true, subtree: true, characterData: true }; observer.observe(mainPageNode, observerConfig);
    }
    else {
    // The ticket isn't closed
    }
    });


  • Alberto_FumagalliAlberto_Fumagalli Customer IT Monkey ✭
    Thanks for you reply and for sharing the code :)
    I had to modify it, by adding a setTimeout call to make the hide() method to work:

    setTimeout(function(){ $('[data-bind="click: addComment"]').hide(); }, 3000);

    Without setTimeout, I experienced the same problem.
    Is such behavior normal? Currently, I've set 3 seconds delay: is this a reliable value or not?




  • Robin_FaklerRobin_Fakler Customer IT Monkey ✭

    I added the above script. The comment button is grayed out but after I type something in the comment field, the button is not grayed out anymore and I´m able to comment on a closed ticket.

    I tried it with and without timeouts.

    Is anyone having the same problem?

  • Mikkel_MadsenMikkel_Madsen Customer Advanced IT Monkey ✭✭✭

    @Robin_Fakler it looks like the page_title does not exist on the closed request page and why not hide the comment iframe too when we are there :)

    Try this code:

    $(document).ready(function () {
    	if (pageForm.viewModel.Status.Name === "Closed") {
    		var mainPageNode = document.getElementById('main_wrapper');
     
    		// create an observer instance
    		var observer = new MutationObserver(function (mutations) {
    			//The page changed. See if our content exists. If it does, then proceed.
    			var contentElement = $(".page_content"); //The content always exists when the form is rendered.
    
    
    			//An element with class of page_title exists.
    			if (contentElement.length > 0) {
    				//We are done observing.  Do not keep running this!
    				observer.disconnect();
    
    
    				//Let's hide the comment iframe and add button
    				$('[data-control="actionLog"]').children('div').first().hide();
    			}
    		});
    
    
    		// configure the observer and start the instance.
    		var observerConfig = { attributes: true, childList: true, subtree: true, characterData: true };
    		observer.observe(mainPageNode, observerConfig);
    	}
    });
    
  • Robin_FaklerRobin_Fakler Customer IT Monkey ✭

    @Mikkel_Madsen thank you for your response but I have the same issue described above.

    The "Is private" button is grayed out but the "Add comment" button is not when I type something in the comment filed.


  • Mikkel_MadsenMikkel_Madsen Customer Advanced IT Monkey ✭✭✭

    @Robin_Fakler the code is not loaded

    Try this and hit F12 to get dev mode og look at the console tab.

    Check if it says that the code is loaded

    $(document).ready(function () {
    	if (pageForm.viewModel.Status.Name === "Closed") {
    		var mainPageNode = document.getElementById('main_wrapper');
     console.log("We are on closed item page");
    		// create an observer instance
    		var observer = new MutationObserver(function (mutations) {
    			//The page changed. See if our content exists. If it does, then proceed.
    			var contentElement = $(".page_content"); //The content always exists when the form is rendered.
    
    console.log("We are looking for page_content");
    			//An element with class of page_title exists.
    			if (contentElement.length > 0) {
    
    console.log("Page content found");
    
    				//Let's hide the comment iframe and add button
    				$('[data-control="actionLog"]').children('div').first().hide();
    				console.log("Actionlog comment disabled");
    //We are done observing.  Do not keep running this!
    				observer.disconnect();
    			}
    		});
    
    
    		// configure the observer and start the instance.
    		var observerConfig = { attributes: true, childList: true, subtree: true, characterData: true };
    		observer.observe(mainPageNode, observerConfig);
    	}
    });
    


  • Robin_FaklerRobin_Fakler Customer IT Monkey ✭
    edited February 2020

    You are right, the code is not loaded.

    I added your code directly in the custom.js - no Logging

    I added your code in a separate file (custom_DisableCommentsOnClosedTickets.js) and tested the following two calls in the custom.js:

    loadScript("/CustomSpace/custom_DisableCommentsOnClosedTickets.js",['/ServiceRequest/','/Incident/']);

    With "loadScript" I get the message "Loaded /CustomSpace/custom_DisableCommentsOnClosedTickets.js" but not the logging messages from your code.

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

    With "getScript" I get nothing in the log.

  • Mikkel_MadsenMikkel_Madsen Customer Advanced IT Monkey ✭✭✭

    Try this with the getscript

    $(document).ready(function () {
    console.log("We are going to hide end user comment function");
    	if (pageForm.viewModel.Status.Name === "Closed") {
    		var mainPageNode = document.getElementById('main_wrapper');
    console.log("We are on closed item page");
    		// create an Observer instance
    		var closedObserver = new MutationObserver(function (mutations) {
    			//The page changed. See if our content exists. If it does, then proceed.
    			var contentElement = $(".page_content"); //The content always exists when the form is rendered.
    console.log("We are looking for page_content");
    			//An element with class of page_title exists.
    			if (contentElement.length > 0) {
    				//We are done observing.  Do not keep running this!
    				closedObserver.disconnect();
    console.log("Page content found");
    				//Let's hide the comment iframe and add button
    				$('[data-control="actionLog"]').children('div').first().hide();
    console.log("Actionlog comment disabled");
    			}
    		});
    
    
    		// configure the Observer and start the instance.
    		var observerConfig = { attributes: true, childList: true, subtree: true, characterData: true };
    		closedObserver.observe(mainPageNode, observerConfig);
    	}
    });
    
  • Robin_FaklerRobin_Fakler Customer IT Monkey ✭

    I found the solution... We have two languages installed in our CIreson environment. I have to use the German word for "closed" in the code.

    if (pageForm.viewModel.Status.Name === "Closed")

    is not working

    if (pageForm.viewModel.Status.Name === "Geschlossen")

    is working :)


    Thank you!

  • Alberto_FumagalliAlberto_Fumagalli Customer IT Monkey ✭

    This kind of issue can be addressed by using the internal enumeration Id.

    For IRs, closed status enum id = bd0ae7c4-3315-2eb3-7933-82dfc482dbaf

    For SRs, closed status enum id = c7b65747-f99e-c108-1e17-3c1062138fc4

    and change the if statement by referencing pageForm.viewModel.Status.Id instead of the name

  • Magnus_LundgrenMagnus_Lundgren Partner IT Monkey ✭

    Thanks so much for this @Mikkel_Madsen

    final code i used for both IR and SR, doesnt matter what language you use


    		//Hide add comment function if SR or IR is closed
    		$(document).ready(function () {
    			var pageLink = window.location.toString();
    			if ((pageLink.indexOf("/Incident/Edit/IR") !== -1)  || (pageLink.indexOf("/ServiceRequest/Edit/SR") !== -1)){
    				var mainPageNode = document.getElementById('main_wrapper');
    		 
    				var observer = new MutationObserver(function (mutations) {
    					var contentElement = $(".page_content");
    
    
    					if (contentElement.length > 0) {
    						observer.disconnect();
    
    
    						//Let's hide the comment iframe and add button
    						if(pageForm.viewModel.Status.Id == "bd0ae7c4-3315-2eb3-7933-82dfc482dbaf" || pageForm.viewModel.Status.Id == "c7b65747-f99e-c108-1e17-3c1062138fc4"){
    							$('[data-control="actionLog"]').children('div').first().hide();
    							console.log("condition found hiding add comment");
    						}
    					}
    				});
    
    
    				var observerConfig = { attributes: true, childList: true, subtree: true, characterData: true };
    				observer.observe(mainPageNode, observerConfig);
    			}
    		});
    
Sign In or Register to comment.