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

Have more questions? Submit a request

73 Comments

  • monique
    Comment actions Permalink

    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
    Comment actions Permalink

    I been trying to get Robbert Hink 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
    Comment actions Permalink

    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
    Comment actions Permalink

    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
    Comment actions Permalink

    This is awesome. Thanks for sharing Fernando!

    0
  • Balazs Brauner
    Comment actions Permalink

    Hi,

    Is there a way to hide forms from unauthenticated users?

     

    Thank you!

    Balazs

    0
  • Gail L
    Comment actions Permalink

    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
    Comment actions Permalink

    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
    Comment actions Permalink

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

    bbysdusers
    0
  • Breonna Bowen
    Comment actions Permalink

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

    0
  • Jaïs Pingouroux
    Comment actions Permalink

    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
    Comment actions Permalink

    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
    Comment actions Permalink

     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

Please sign in to leave a comment.

Powered by Zendesk