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

Return to top
Have more questions? Submit a request

78 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 - Community Manager
    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 - Community Manager
    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.

    0
  • 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);
    });

    });
    0
  • Søren Poulsen

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

    0

Please sign in to leave a comment.

Powered by Zendesk