IT Monkey:   


Formal Cireson Support (phone, email, and web) is not included with the free Self-Service Portal – Community app. For trouble shooting assistance, take advantage of the Cireson Community to find answers to your questions. However, if you’d like to purchase a Support Package to access more formal Cireson Support (phone, email, and web), please contact us today to learn more on the pricing options.

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?




Sign In or Register to comment.