How can I hide ticket forms based on a user's organization?

Return to top
Have more questions? Submit a request

78 Comments

  • Drew Hayes

    @Ryan, 

    Thanks for sharing! As I am not an experienced coder by any means, would you please point out which portions of your code need to be replaced (forms, tags, etc.) within your example before I try to implement it and get something wrong? I tried in testing a bit, but apparently did something incorrect. 

    0
  • Ryan M Mayes

    Hi Drew,

    Using the code as-is, add a prefix to each ticket form name that matches a tag on the users that you want to see that ticket form.

    For example:

    User John has tag "learner". If you rename a ticket form to "learner - repair form", John will be able to see the form, but other users who do not have the "learner" tag will not be able to see the form.

    -Ryan

    1
  • Drew Hayes

    Ahh - Thanks, Ryan. That makes sense. Too easy - I was trying to over complicate it! :) 

    0
  • Jessie Schutz
    Zendesk team member

    Hey Ryan! 

    Thank you so much for coming back to answer questions about your comment! If you'd like, feel free to write it up for our Tips & Tricks topic. You'll get swag in addition to fame. :)

    0
  • Dan Derks

    Hi Ryan!

    In the midst of expanding my org's use of ZenDesk to include internal support. I want to create a form that only folks who are tagged with 'isr' (Internal Support Requester) can see. I copied your original code into my script.js file and have renamed a form 'ISR - request', but the form remains publicly available.

    Any guidance (though you've provided more than enough over the years!) would be appreciated :)

    Best,

    Dan

    0
  • Mike West

    What's the best method for hiding a specific form always, regardless of the user's organization or any other criteria?

    I have a form that I'd like to link to from a very specific Help Center article only. I don't want a user to ever be able to select this form from the drop-down list.

    Thanks in advance.

     

    0
  • Jessie Schutz
    Zendesk team member

    Hi Mike!

    I imagine that you can use code similar to this to hide the form from all users, rather than just certain users. All this does is remove it from the dropdown so users can't select it - the form still exists, and you should be able to link directly to it. I can't help with code specifics but we have plenty of helpful tips provided by community members that can help get you started!

    0
  • Uriel Flores

    Hello,

     

    We currently have 1 default form, which all organizations use. We included an additional form for 8 organizations that have an additional service, aside from their current. We used the script above and successfully works. However, is there a method that we can use for all organizations that do not have the additional service that we offer, be directed straight to our default form, instead of having to select the default form from the drop-down menu? Currently, organizations that do not have our additional service, have to click the default form to submit a regular ticket, which is an additional step for them (other form is hidden). Is there a way to show our 8 organizations the two different forms only, and not have the other organizations have to select the only form that they need to submit a ticket and just be directed to the default ticket form?

     

    Thanks.

    0
  • Fernando Duarte

    I would give those users a direct link to the specific form rather to the forms page

    0
  • Anders Vännman

    Pew. This was advanced for a much needed feature. Would be so much nicer if one it was possible to do this right from the admin interface, where i create the ticket forms, a field "show only for  these organisations" and "show only for users with these tags", or something similar.

     

    6
  • Xavi

    @Ryan, thanks for sharing your code.

    Does it mean that all users shall have a tag corresponding to the prefix of every form they need to access ?

    For example :

    I have a form called "General" and i want all my users to be able to access this form. So, with your code, all my users shall have a tag "General"?

    The problem would be forgetting to add this tag when we add 1 new user.

    Thanks in advance

    0
  • Steve Morrell

    We have implemented this, and it is mostly working well. However, it seems that remove() is not supported on IE11, so users are seeing multiple forms for this.

    https://stackoverflow.com/questions/20428877/javascript-remove-doesnt-work-in-ie

    So far the suggestions in the above article haven't worked. Does anyone have any other thoughts?

    0
  • Wesley Bowles

    Can anyone help me with the JS i would need for the following? I've read through most of the previous comments and most of the modifications don't seem to quite match up with what i need. 

    We only have two forms. Our default and "form2". Basically we only want users with a specific user tag to see "form2" in addition to our default form. everyone else without this tag would only see the default form. 

    Thank you in advance for any assistance. 

    0
  • Kay
    Community Moderator

    Hi Wesley,

    This should point you in the right direction.

    ⚠️This snippet of code is quickly written, have your developer check against this.

    // only on the new request page and only if the user does not have a certain tag
    if(window.location.href.indexOf("/requests/new") > -1
    && !HelpCenter.user.tags.includes('VIP')) {

    // the form ID that needs to be hidden
    var formID = "74185";

    // remove from DOM, the select option and the UI by Zendesk
    document.querySelector('.request_ticket_form_id > a.nesty-input').addEventListener('click', removeItem);
    document.querySelector('#request_issue_type_select option[value~="'+formID+'"]').remove();

    // remove the element from DOM
    function removeItem(){
    var el = document.getElementById(formID);
    if(el) el.remove();
    }
    }

     

    0
  • Justin

    Can we hide a ticket form from the drop down for ALL users regardless of org? The form would only be accessibly via a direct link...

    1
  • Wesley Bowles

    Kay Thank you, that worked like a charm with some slight modification. 

    0
  • Alex Gillum-Webb

    Hi folks,

    Looking for some advice on hiding a button on our home page (essentially submit a request) unless it is a specific Organization (either by ID, name or Tags).

    So far I have given the button an ID 'tamper' on the home page:

    <form style="display: block; text-align: center; margin: 20px;" class="submitbutton"
    action="{{page_path 'new_request'}}">
    <input type="submit" id="tamper" value="Tamper Label Upload">
    </form>

    Next I have set the button to be hidden by default in style.css:
    #tamper {
    display: none;
    }

     So far so good. I'm having trouble getting a function into the javascript to work. So far I have tried Robberts code with alteration (in bold):

     

    $(window).load(function() {
    var i = 0;
    var checkExist = setInterval(function() {
    i++;
    if ($("a.nesty-input").length){
    clearInterval(checkExist);
    $("a.nesty-input").each(function() {
    $(this).bind( "click", function() {
    for (var c in HelpCenter.user.organizations) {
    if (HelpCenter.user.organizations[c].name == "Test Org"){
    $("#tamper").show();
    }

    //reserve space for additional organizations
    }

    });
    });
    }
    if (i > 10){
    clearInterval(checkExist);
    }
    }, 100);
    });

    But I can't seem to get it to work. Where abouts in the the JS would this function need to sit?

    0
  • Brett Bowser
    Zendesk Community Team

    Hey Alex,

    I'm rather limited on what I can assist with on my end but I was able to track down the following tip that may help point you in the right direction:

    Hide/show community based on organization tags

    Hopefully, other users can jump in and offer up some guidance as well :)

    Cheers!

    0
  • Jaïs Pingouroux

    Hello,

    This JS workaround works well for forms on the Help Center, but what about forms in the Widget?

    Is there a way to interact with the widget's code to add the relevant JS to hide some of the forms depending on the current user's organization?

    0
  • Simon Blouner
    Community Moderator

    Hey @Jaïs Pingouroux

    You should be able to combine the tip from Brett, with some other custom Widget Scripting.

    So in the If check in the JS, you could add the something like this:

    window.zESettings = {
       "webWidget": {
          "contactForm": {
             "ticketForms": [
                {
                   "id": "123456789"
                },
                {
                   "id": " 987654321"
                }
             ]
          }
       }
    }

    #helpsome regards,
    Simon Blouner
    Zendesk Consultant @ helphouse.io

    0
  • Jaïs Pingouroux

    Thanks Simon Blouner, I'll see if I can use that when the widget is set on a platform with a JWT token

    0
  • Stassa Miller
    Community Moderator

    Is there a way to hide the forms from indiividual end-users?

    Example, I want Jane and John Doe only to see User access forms.  I do not want them to submit any other type of tickets.

    0
  • Stassa Miller
    Community Moderator

    Let me try Kay's entry and come back to this post.

     

    0
  • Lior Broshi

    Here's my solution that allows you to define a form name:
    'Form Name [ONLY: Organization-here]' 
    Which will make the form appear only for an end-user (or agent) from that organization.

    This way you don't need to manage tags or groups, just limit forms to specific organizations.

    Source code is available here

    0
  • David Quiram

    So help me understand this a little better. It removes visibility of a ticket from a specific group.

    I have specific forms for our HR Dept. We have all our users grouped into orgs that match their departments. With this coding, I will have to list out every org EXECEPT HR and also list out the hr specific ticket forms so that those orgs don't see the HR forms. Right?

    Can this coding accept multiple orgs and forms in the same block section or will I have to do this one org at a time?

    0
  • Lior Broshi

    David Quiram
    By default - all forms are available to everyone.
    But if you name the form with "[ONLY: organization]" - only members of that organization will see the form.

    Example:
    1. Incident Form
    2. Incident Form [ONLY: HR] <-- will be available only to a user who has "HR" in the list of organizations.

    Currently it supports just one Organization, but I can modify it to support multiple orgs so it will be
    "Incident Form [ONLY: HR,Finance,Helpdesk]" if that helps.

    0
  • Judy Dolton

    Kay  Thank you for your code to help hide a form based on a user tag.  It worked great!   We don't have a developer onsite so pardon my question - how could we update it to exclude multiple forms based on a user tag?  

    Update - I think I'm good now.  I was able to hide multiple forms finally.  :-)

     

    0
  • Nicole S.
    Zendesk Community Team

    Glad to hear you got things sorted, Judy! 

    Also, I see that this is your first post. Welcome to the Zendesk Community! If you'd like to introduce yourself to everyone, you can do so here

    0
  • Seth Weingarten

    Lior Broshi Where do I insert the code you listed above?

    0
  • Lior Broshi

    Seth Weingarten at the end of script.js of your template.

    0

Please sign in to leave a comment.

Powered by Zendesk