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

Return to top
Have more questions? Submit a request

92 Comments

  • monique

    Hi All,

     

    I have read through the comments and I am having a little trouble with the code recognizing the tags for the end users.  The code I am currently using removes the ticket form for all users instead of the users with the specific "temporaryuser" tag. If I can have some guidance as to what I may be doing wrong I would appreciate it.

    $(window).load(function() {
    var i = 0;
    var cForm1 = false; 

    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.tags) {
    if (HelpCenter.user.tags[c].tag == "temporaryuser"){
    cForm1 = true; 
    }

    }
    if (!cForm1){
    $("#360000818671").remove(); 
    $("#360000716471").remove();
    }

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

    0
  • Juan Gomez

    I been trying to get @... code to work and it just hasn't taken. am i missing something here? can someone please assist in trying to figure this out? what am i missing here? Im unfortunately not the best in coding. 

    I placed it at the end of the script. 

    0
  • Brett Bowser
    Zendesk Community Team

    Hey Juan,

    It looks like you haven't received a response on this comment yet. I'm rather limited on what I can assist with on my end but wanted to check to see if you were able to get this issue resolved?

    If you have developers available, it may be worth having them take a look at your theme to confirm there's no conflicting code. Additionally, if the issue persists, are you receiving some sort of error on your end?

    Any additional information you can provide may help other users troubleshoot the issue.

    Keep us posted!

    0
  • Fernando Duarte

    Simply copy the following code at the bottom of your script.js and change the values for the forms as needed:

     

      // Hiding forms

    var i = 0;
    var checkExist = setInterval(function() {
    i++;
    if ($("a.nesty-input").length){
    clearInterval(checkExist);
    $("a.nesty-input").each(function() {
    $(this).bind( "click", function() {

    // Hide form 1234567 from everyone
    $("#1234567").remove();

    // Check if user has tag "no_form"
    if (orgTags.indexOf("no_form") < 0){

    // Hide Specific forms when the tag "no_form" is missing

    // Hide form 567890
    $("#567890").remove();
    // Hide form 98765
    $("#98765").remove();
    // Hide form 543621
    $("#543621").remove();

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

     

    0
  • Brett Bowser
    Zendesk Community Team

    This is awesome. Thanks for sharing Fernando!

    0
  • Balazs Brauner

    Hi,

    Is there a way to hide forms from unauthenticated users?

     

    Thank you!

    Balazs

    0
  • Gail L
    Zendesk Community Team

    Hi Balazs,

    The best way to hide the forms from unauthenticated users would be to require sign-in on your help center. The web widget doesn't require authentication to use, so if you're using it the only way to limit access to the forms on it is to install it on a page that isn't generally accessible without sign-in.

    0
  • Breonna Bowen

    Sadly, none of the recommended solutions are working for me. I attempted Robert's and Fernando's recommendations several times and with: 

     

    Robert's it hide the form from all users and with Fernando's the form is viewable by all users. 

    Can someone tell me what I'm doing wrong?: 

    Fernando's attempt 

    // Hiding forms

    var i = 0;
    var checkExist = setInterval(function() {
    i++;
    if ($("a.nesty-input").length){
    clearInterval(checkExist);
    $("a.nesty-input").each(function() {
    $(this).bind( "click", function() {

    // Check if user has tag "no_form"
    if (orgTags.indexOf("bbysdusers") < 0){

    // Hide Specific forms when the tag "no_form" is missing

    // Hide form 360002863493
    $("#360002863493").remove();

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



     

    Robert's attempt: 

    $(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 !== " CLIENT NAME SmartDisposition Rule Requests"){
    $("#360002863493").remove();
    }

    //reserve space for additional organizations
    }

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

     

    0
  • Fernando Duarte

    Breonna Bowen Did you add the following tag to the user/organization that you tested with?

    bbysdusers
    0
  • Breonna Bowen

    @Fernando Durante Yes, and it's still showing for all users. 

    0
  • Jaïs Pingouroux

    Alternate method:

    1) Set organization tags to discreminate which organizations should/shouldn't hide fields (ex: "org_internal", "org_partner", "org_customer" ...)

    2) Adapt the code:

    ```

    // Remove forms

    $(window).load(function() {
    var i = 0;
    var remove_forms = true;
    for (var c in HelpCenter.user.organizations) {
    if (HelpCenter.user.organizations[c].tags.includes("org_internal")){
    remove_forms = false;
    }
    }
    var checkExist = setInterval(function() {
    i++;
    // Remove product field
    if ($('.request_custom_fields_360009259653').length && remove_forms){
    $('.request_custom_fields_360009259653').remove();
    }

    if ($("a.nesty-input").length){
    clearInterval(checkExist);
    $("a.nesty-input").each(function() {
    $(this).bind( "click", function() {
    // Always remove this request type
    $('#request_issue_type_select option[value="360000473999"]').remove();
    $("#360000473999").remove();

    // Remove these forms based on Organization
    if (remove_forms){
    // Form 1
    $('#request_issue_type_select option[value="360001709733"]').remove();
    $("#360001709733").remove();
    // Form 2
    $('#request_issue_type_select option[value="360000223093"]').remove();
    $("#360000223093").remove();
    }
    });
    });
    }
    if (i > 20){
    clearInterval(checkExist);
    }
    }, 100);
    });

    ```

    0
  • David Quiram

    At this point is Zendesk ever going to build this into their platform as an actual supported function? There's an obvious need by many for this functionality.

    1
  • Jaïs Pingouroux

     David Quiram  where there's hope, there's life.

    But you have more chance to win at the national lottery than having Zendesk answer positively to one of your Feature Requests. Put your hands in the dirt of code and workarounds, you'll have better luck. ;)

    0
  • Rachel M

    I've also tried to use both the article's code and Fernando Duarte's code. the closest i got was with fernando's – the "hide form from everyone" option worked, but i using org, user tags or org tags i hit a wall.

    now i'm using "potato" as the tag. no one has that anywhere – so i'd expect no one could see the form. and yet, there it stays...



    var i = 0;
    var checkExist = setInterval(function() {
    i++;
    if ($("a.nesty-input").length){
    clearInterval(checkExist);
    $("a.nesty-input").each(function() {
    $(this).bind( "click", function() {

    // Check if user has tag "potato"
    if (orgTags.indexOf("potato") < 0){

    // Hide Specific forms when the tag "potato" is missing

    // Hide form 360000682534
    $("#360000682534").remove();


    }
    });
    });
    }
    if (i > 10){
    clearInterval(checkExist);
    }
    }, 100);
    0
  • Jaïs Pingouroux

    Hi Rachel M

    How or where do you define you orgTags variable?

    0
  • Søren Poulsen

    I am struggling a bit with a variation of different comments in this comment thread. Has anyone been succesful in removing a specific form field but not an entire form based on organisation? 

    I have only 1 form but want to remove a single input field based on the organisation the end-user belongs to. 

    Thanks! 

    0
  • Jaïs Pingouroux

    Søren Poulsen it's quite easy, you'd have something like this:

     

    $(window).load(function() {
    var i = 0;
    var my_condition = false;
    for (var c in HelpCenter.user.organizations) {
    // Set your conditions here
    // Example with Org tags
    if (HelpCenter.user.organizations[c].tags.includes("A_SPECIAL_TAG")){
    my_condition = true;
    }
    // Example with Org Name
    if (HelpCenter.user.organizations[c].name == "A_SPECIAL_NAME"){
    my_condition = true;
    }
    }
    var checkExist = setInterval(function() {
    i++;
    // Remove custom field XXX
    if ($('.request_custom_fields_XXX').length && my_condition){
    $('.request_custom_fields_XXX').remove();
    }

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

    });
    1
  • Søren Poulsen

    Jaïs Pingouroux This is great, that is exactly what I was looking for. Thank you :) 

    0
  • Björn Ljungborg

    Hi, I am trying to Hide internal forms from clients

    I am using this code with modifications at the end of the script.js but it is not removing them with clients logged on with the "Client" organization

    $(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 !== "Client"){
    $("#360005169014").remove();
    }

    //reserve space for additional organizations
    }

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

     

    Not sure what I am missing

    We are on professional with prod add on pack

     

     

    0
  • Jaïs Pingouroux

     

    Hi @björn Ljungbord

    You may want to change 

    if (HelpCenter.user.organizations[c].name !== "Client")

    into

    if (HelpCenter.user.organizations[c].name == "Client")

     

    0
  • Carl Goldberg

    You may need to add a jQuery CDN to the Help Center's document_head.hbs. Previous versions of Help Center included jQuery by default but the built-in dependency has been removed so you'll need to add it yourself if you use jQuery, upon which this snippet depends. 

    0
  • Ruddy DEROSIERS

    Hi,

    Does anyone have updated this in VanillaJs instead of Jquery ?

    My code worked fine in V1 with Jquery but not in V2 (with JQUERY in document_head).

    thanks a lot

    0
  • Ron de Vries

    Hi, 

    Maybe just a shot in the dark but... does anyone know how to show the comments only to a particular User Segment or Organisation? Or perhaps on a specific tag of that organisation or end-user. Background of this request is that we only want our own employees to comment on articles (for now). 

    Can I alternate one of the codes in the comments of this article or would you suggest to use one of the built in Helpers? It would concer the <div class="article-comments" id="article-comments"> section. 

    Any help is much appreciated! 

    Regards, 

    Ron

    0
  • Jaïs Pingouroux

    Hi Ron de Vries

    Based on what has been posted before, you want to add the following code to your template:

    In style.css:

    #article-comments{
    display: none;
    }

    In script.js:

    // Check organization
    var i = 0;
    for (var c in HelpCenter.user.organizations) {
    if (HelpCenter.user.organizations[c].tags.includes("YOUR_ORG_TAG")){
    $("#article-comments").show();
    }
    }

    It's untested but it should work.

    1
  • Ron de Vries

    HI Jaïs Pingouroux

    Thanks! I will give it a try. Since we are using the Single Sign On as well I will also consult with our Dev Team.

    I will get back on it once we have it up and running so other members of the community can benefit as well.

    Regards,

    Ron

    0
  • Jaïs Pingouroux

    Ron de Vries SSO is not really a problem, as your organization's tags are still defined in Zendesk (admin>people>organizations). Alternatively you could use your organization's name instead of a tag if it's better for you and if you only have to deal with one single entity.

    0
  • Ron de Vries

    Hi Jaïs Pingouroux

    Thanks for jumping in. The .css works just fine however the JS code doesn't render as expected. I did assign the tag (comments_visible) to the organisation within ZenDesk. Maybe you're able to assist with the code for checking on the organisation name as well? 

    Am I right that the code should be under the $(document).ready(function() { function? 

    Just to be complete, this is the code I tried and didn't work out:

    $(document).ready(function() {
    // Check organization
    var i = 0;
    for (var c in HelpCenter.user.organizations) {
    if (HelpCenter.user.organizations[c].tags.includes("comments_visible")){
    $("#article-comments").show();
    }
    }

    And this is the organisation with the tag: 

    0
  • Jaïs Pingouroux

    Hi Ron de Vries

    Your code should be in the script.js file of your template, you probably already have some code in here.

    If you want to make sure that you're running in your loop, you can add this line of code before in the For loop right before the if statement.

    console.log(HelpCenter.user.organizations[c].tags);

    You'll see the result in the console tab of your web browser.

    Are you testing the code with a logged in user of this organization?

    0
  • Ron de Vries

    Hi Jaïs Pingouroux

    My mistake; I placed to code after the $(document).ready(function(){. Guess I was too hasty. Nevertheless, it works perfect now with the code you provided. 

    Many thanks!! 

    Regards,

    Ron

    0
  • Conor M.

    I've been testing Ryan Mayes's solution for this issue (see code block below), but hit a snag that I haven't seen addressed here. Here's what Ryan shared:

    $(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() {
                        //Create dictionary of available forms
                        var forms = {}
                        var options = document.getElementById("request_issue_type_select").getElementsByTagName("option");
                        for (i = 1; i < options.length; i++) {
                            forms[options[i].text] = options[i].value;
                        };
                        //Iterate through each form 
                        Object.keys(forms).forEach(function(item){
                            formTag = item.split(" - ")[0].toLowerCase();
                            //Remove forms that do not meet user criteria
                            if (!(~HelpCenter.user.tags.indexOf(formTag))){
                                $(("#"+forms[item])).remove();
    //Add this to hide form "tags" from user view
    }else{
    $(("#"+forms[item])).text(item.split(" - ")[1]);
    } }); }); }); } if (i > 10){ clearInterval(checkExist); } }, 100); });

    Now here's my problem: when looking at the dropdown when this code is present, everything looks fine. For example, a form titled "test_tag - Ticket Form 1" will appear as "Ticket Form 1". This is exactly what I want to see in the dropdown.

    Unfortunately, once I click on "Ticket Form 1" and the actual form loads, the selection in the dropdown field shows the form's name as "test_tag - Ticket Form 1". Clicking on the dropdown again shows the available forms as desired (no tags visible), but whenever one is selected it appears with the tag. 

    Here are the ticket forms as they appear in the dropdown:

    And here's what it looks like when I select one:

    Any ideas on how to resolve this issue? We're using some really long and ugly tags on our side and I can't have them showing up in the form name. 

    0

Please sign in to leave a comment.

Powered by Zendesk