Making a custom Form only visible to a particular Organization

Answered

26 Comments

  • Ryan

    Hi Anton Van der meyden!

    I do this using tags. Create a unique tag for the org and then enter this code into the script.js. This example is for an internal IT ticket only visible to my org.

    Hope this is helpful!

    Ryan

     

    $(document).ready(function() {

    Internal = []

    for (var c in HelpCenter.user.organizations){
    if (HelpCenter.user.organizations[c].tags.indexOf(' YOUR_TAG_HERE ') > -1){
    Internal = "Yes";
    }
    }
    if (Internal == "Yes"){
    console.log('user is an employee');
    }
    else{
    $('#request_issue_type_selectoption[value=" YOUR_FORM_ID#_HERE "]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){
    $(this).children('ul').children().remove('#YOUR_FORM_ID#_HERE ');
    });
    console.log('user is a customer');
    }
    });

     

    1
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    The following script will hide the custom form on the drop down as well as restrict access to the form if a user's organization does not equal the value you provide in the script.

    You will need to add this script to your script.js page, within the $(document).ready(function() { . You could scroll all the way to the bottom of the script.js page if it is all part of the .ready and make sure the script is inserted within last });

     

     if (HelpCenter.user.organizations[0].name != "ORGANIZATIONNAME"){
    $('#request_issue_type_select option[value="CUSTOMFORMIDHERE"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#CUSTOMFORMIDHERE');
    });
    }

    Be sure to update the bolded parts in the script: ORGANIZATIONNAME = The Organization name you want the form to be visible to, CUSTOMFORIDHERE = The Form ID in which you want to hide if the user is not part of the Organization you identified. Please let me know if you have any questions. Thank you.

    1
  • Ryan

    I agree with Socorro Fernandez. If you don't have any orgs that have the same name, thats the best way to go. Unfortunately, we orgs that share the same name so I have to use the tag method.

    0
  • Socorro Fernandez
    Community Moderator

    Looks like we posted around the same time Ryan!

    Tag method is also a great option!

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

    Thank you both for you help.

     

    Socorro can you please assist me further with this. 

     

    As the organization does not duplicate I'm trying to use Socorro method but the form is still showing to anyone and  not the specific organization.

     

    Here is a screenshot of the test organization I made:

    Here is the Test form ID:

    Here is the code I used:

    I added your code to the bottom of the script.js and to the top below $(document).ready(function()  but did not work in either position.

     

    /*
    * jQuery v1.9.1 included
    */

    $(document).ready(function() {

    // social share popups
    $(".share a").click(function(e) {
    e.preventDefault();
    window.open(this.href, "", "height = 500, width = 500");
    });

    // show form controls when the textarea receives focus or backbutton is used and value exists
    var $commentContainerTextarea = $(".comment-container textarea"),
    $commentContainerFormControls = $(".comment-form-controls, .comment-ccs");

    $commentContainerTextarea.one("focus", function() {
    $commentContainerFormControls.show();
    });

    if ($commentContainerTextarea.val() !== "") {
    $commentContainerFormControls.show();
    }

    // Expand Request comment form when Add to conversation is clicked
    var $showRequestCommentContainerTrigger = $(".request-container .comment-container .comment-show-container"),
    $requestCommentFields = $(".request-container .comment-container .comment-fields"),
    $requestCommentSubmit = $(".request-container .comment-container .request-submit-comment");

    $showRequestCommentContainerTrigger.on("click", function() {
    $showRequestCommentContainerTrigger.hide();
    $requestCommentFields.show();
    $requestCommentSubmit.show();
    $commentContainerTextarea.focus();
    });

    // Mark as solved button
    var $requestMarkAsSolvedButton = $(".request-container .mark-as-solved:not([data-disabled])"),
    $requestMarkAsSolvedCheckbox = $(".request-container .comment-container input[type=checkbox]"),
    $requestCommentSubmitButton = $(".request-container .comment-container input[type=submit]");

    $requestMarkAsSolvedButton.on("click", function () {
    $requestMarkAsSolvedCheckbox.attr("checked", true);
    $requestCommentSubmitButton.prop("disabled", true);
    $(this).attr("data-disabled", true).closest("form").submit();
    });

    // Change Mark as solved text according to whether comment is filled
    var $requestCommentTextarea = $(".request-container .comment-container textarea");

    $requestCommentTextarea.on("input", function() {
    if ($requestCommentTextarea.val() !== "") {
    $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-and-submit-translation"));
    $requestCommentSubmitButton.prop("disabled", false);
    } else {
    $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-translation"));
    $requestCommentSubmitButton.prop("disabled", true);
    }
    });

    // Disable submit button if textarea is empty
    if ($requestCommentTextarea.val() === "") {
    $requestCommentSubmitButton.prop("disabled", true);
    }

    // Submit requests filter form in the request list page
    $("#request-status-select, #request-organization-select")
    .on("change", function() {
    search();
    });

    // Submit requests filter form in the request list page
    $("#quick-search").on("keypress", function(e) {
    if (e.which === 13) {
    search();
    }
    });

    function search() {
    window.location.search = $.param({
    query: $("#quick-search").val(),
    status: $("#request-status-select").val(),
    organization_id: $("#request-organization-select").val()
    });
    }

    function toggleNavigation(toggleElement) {
    var menu = document.getElementById("user-nav");
    var isExpanded = menu.getAttribute("aria-expanded") === "true";
    menu.setAttribute("aria-expanded", !isExpanded);
    toggleElement.setAttribute("aria-expanded", !isExpanded);
    }

    $(".header .icon-menu").on("click", function(e) {
    e.stopPropagation();
    toggleNavigation(this);
    });

    $(".header .icon-menu").on("keyup", function(e) {
    if (e.keyCode === 13) { // Enter key
    e.stopPropagation();
    toggleNavigation(this);
    }
    });

    $("#user-nav").on("keyup", function(e) {
    if (e.keyCode === 27) { // Escape key
    e.stopPropagation();
    this.setAttribute("aria-expanded", false);
    $(".header .icon-menu").attr("aria-expanded", false);
    }
    });

    if ($("#user-nav").children().length === 0) {
    $(".header .icon-menu").hide();
    }

    // Submit organization form in the request page
    $("#request-organization select").on("change", function() {
    this.form.submit();
    });

    // Toggles expanded aria to collapsible elements
    $(".collapsible-nav, .collapsible-sidebar").on("click", function(e) {
    e.stopPropagation();
    var isExpanded = this.getAttribute("aria-expanded") === "true";
    this.setAttribute("aria-expanded", !isExpanded);
    });

    //Added your code here inside the last brackets

    if (HelpCenter.user.organizations[0].name != "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('360002822914');
    });
    }


    });


    // Change text 'Submit request'
    $('.submit-a-request').html('Submit a Query');

     

    Kind Regards

    Anton

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    It looks like you are missing the # before the form id on the 3rd line:

    if (HelpCenter.user.organizations[0].name != "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }

    Add the # and see if you get different results. If it still doesnt work, I see the //Change text 'Submit request' code that is not within the document.ready. If you move that code to be before the }); , do you have different results? 

    Please let me know. Thanks!

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

    Thank you for the reply.

    I did try it previously with the # but it did not work so I removed it.

    I have tried it again. See code below:

     

    I have also tried adding the submit a request before the last }];. Unfortunately this does not work either.

    When I go to the Help center the form is still visible to everyone and not just the organization.

    Can't figure out what I'm missing. 

    Can you provide any more insight into this?

    Kind Regards,

    Anton

     

     

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    At the end of both your examples, there seems to be an extra set of the closing brackets "});" when i copied and pasted your code into a default copenhagen theme, it was causing an error and even the script to update the text of submit request was not working . I was able to get it to work with the following:

    Update the end of your page to look like this instead, From your last example, All I did was remove the closing brackets right above the // Change text 'Submit request'

    //Added your code here inside thee last brackets 

    if (HelpCenter.user.organizations[0].name != "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }

    // Change text 'Submit request'
    $('.submit-a-request').html('Submit a Query');

    });

    I hope this clears it up but please let me know. Thank you!

     

    EDIT: Updated first line of code to reflect != for does not equal to from == equal

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

    Thank you for the update but unfortunately this did not work.

     

    Here is the code I used at the end of the script.js page. I copy and pasted your text.

     

    // Toggles expanded aria to collapsible elements
    $(".collapsible-nav, .collapsible-sidebar").on("click", function(e) {
    e.stopPropagation();
    var isExpanded = this.getAttribute("aria-expanded") === "true";
    this.setAttribute("aria-expanded", !isExpanded);
    });

    //Added your code here inside thee last brackets

    if (HelpCenter.user.organizations[0].name == "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }

    // Change text 'Submit request'
    $('.submit-a-request').html('Submit a Query');

    });

    You can see in this screenshot when I go to the Help Centre as an end user all forms and the test form is still visible to anyone. I'm using a custom theme but I don't think this should impact the code.

    Can you please assist again with this?

    Thank you very much.

     

    Kind Regards,

    Anton

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    I found a mistake in my first line of code on my latest post. The == means equal and that if you do have AntonTest as your organization, it will remove it for you. Update ==  to != so its does not equal and meaning anyone who isn't part of AntonTest organization will have it removed:

     

    if (HelpCenter.user.organizations[0].name != "AntonTest"){

     

    Just showing the first line to update , the rest looks good on your screenshot. If the issue persists, maybe you can test the code on the copenhagen theme so we can at least confirm it is working.

     

    Thank you

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

     

    Good news.The code worked worked on the Copenhagen theme on another Help Center but won't work on the custom theme that I'm using.

    I have added the code below for the Copenhagen theme with your code added that works:

    /*
    * jQuery v1.9.1 included
    */

    $(document).ready(function() {

    // social share popups
    $(".share a").click(function(e) {
    e.preventDefault();
    window.open(this.href, "", "height = 500, width = 500");
    });

    // show form controls when the textarea receives focus or backbutton is used and value exists
    var $commentContainerTextarea = $(".comment-container textarea"),
    $commentContainerFormControls = $(".comment-form-controls, .comment-ccs");

    $commentContainerTextarea.one("focus", function() {
    $commentContainerFormControls.show();
    });

    if ($commentContainerTextarea.val() !== "") {
    $commentContainerFormControls.show();
    }

    // Expand Request comment form when Add to conversation is clicked
    var $showRequestCommentContainerTrigger = $(".request-container .comment-container .comment-show-container"),
    $requestCommentFields = $(".request-container .comment-container .comment-fields"),
    $requestCommentSubmit = $(".request-container .comment-container .request-submit-comment");

    $showRequestCommentContainerTrigger.on("click", function() {
    $showRequestCommentContainerTrigger.hide();
    $requestCommentFields.show();
    $requestCommentSubmit.show();
    $commentContainerTextarea.focus();
    });

    // Mark as solved button
    var $requestMarkAsSolvedButton = $(".request-container .mark-as-solved:not([data-disabled])"),
    $requestMarkAsSolvedCheckbox = $(".request-container .comment-container input[type=checkbox]"),
    $requestCommentSubmitButton = $(".request-container .comment-container input[type=submit]");

    $requestMarkAsSolvedButton.on("click", function () {
    $requestMarkAsSolvedCheckbox.attr("checked", true);
    $requestCommentSubmitButton.prop("disabled", true);
    $(this).attr("data-disabled", true).closest("form").submit();
    });

    // Change Mark as solved text according to whether comment is filled
    var $requestCommentTextarea = $(".request-container .comment-container textarea");

    $requestCommentTextarea.on("keyup", function() {
    if ($requestCommentTextarea.val() !== "") {
    $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-and-submit-translation"));
    $requestCommentSubmitButton.prop("disabled", false);
    } else {
    $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-translation"));
    $requestCommentSubmitButton.prop("disabled", true);
    }
    });

    // Disable submit button if textarea is empty
    if ($requestCommentTextarea.val() === "") {
    $requestCommentSubmitButton.prop("disabled", true);
    }

    // Submit requests filter form in the request list page
    $("#request-status-select, #request-organization-select")
    .on("change", function() {
    search();
    });

    // Submit requests filter form in the request list page
    $("#quick-search").on("keypress", function(e) {
    if (e.which === 13) {
    search();
    }
    });

    function search() {
    window.location.search = $.param({
    query: $("#quick-search").val(),
    status: $("#request-status-select").val(),
    organization_id: $("#request-organization-select").val()
    });
    }

    $(".header .icon-menu").on("click", function(e) {
    e.stopPropagation();
    var menu = document.getElementById("user-nav");
    var isExpanded = menu.getAttribute("aria-expanded") === "true";
    menu.setAttribute("aria-expanded", !isExpanded);
    });

    if ($("#user-nav").children().length === 0) {
    $(".header .icon-menu").hide();
    }

    // Submit organization form in the request page
    $("#request-organization select").on("change", function() {
    this.form.submit();
    });

    // Toggles expanded aria to collapsible elements
    $(".collapsible-nav, .collapsible-sidebar").on("click", function(e) {
    e.stopPropagation();
    var isExpanded = this.getAttribute("aria-expanded") === "true";
    this.setAttribute("aria-expanded", !isExpanded);
    });

    //Added your code here inside thee last brackets

    if (HelpCenter.user.organizations[0].name != "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }

    // Change text 'Submit request'
    $('.submit-a-request').html('Submit a Query');


    });

     

    Here is code in custom theme that does not work:

     

    Script Page before editing

    /*
    * jQuery v1.9.1 included
    */

    $(document).ready(function() {

    // social share popups
    $(".share a").click(function(e) {
    e.preventDefault();
    window.open(this.href, "", "height = 500, width = 500");
    });

    // show form controls when the textarea receives focus or backbutton is used and value exists
    var $commentContainerTextarea = $(".comment-container textarea"),
    $commentContainerFormControls = $(".comment-form-controls, .comment-ccs");

    $commentContainerTextarea.one("focus", function() {
    $commentContainerFormControls.show();
    });

    if ($commentContainerTextarea.val() !== "") {
    $commentContainerFormControls.show();
    }

    // Expand Request comment form when Add to conversation is clicked
    var $showRequestCommentContainerTrigger = $(".request-container .comment-container .comment-show-container"),
    $requestCommentFields = $(".request-container .comment-container .comment-fields"),
    $requestCommentSubmit = $(".request-container .comment-container .request-submit-comment");

    $showRequestCommentContainerTrigger.on("click", function() {
    $showRequestCommentContainerTrigger.hide();
    $requestCommentFields.show();
    $requestCommentSubmit.show();
    $commentContainerTextarea.focus();
    });

    // Mark as solved button
    var $requestMarkAsSolvedButton = $(".request-container .mark-as-solved:not([data-disabled])"),
    $requestMarkAsSolvedCheckbox = $(".request-container .comment-container input[type=checkbox]"),
    $requestCommentSubmitButton = $(".request-container .comment-container input[type=submit]");

    $requestMarkAsSolvedButton.on("click", function () {
    $requestMarkAsSolvedCheckbox.attr("checked", true);
    $requestCommentSubmitButton.prop("disabled", true);
    $(this).attr("data-disabled", true).closest("form").submit();
    });

    // Change Mark as solved text according to whether comment is filled
    var $requestCommentTextarea = $(".request-container .comment-container textarea");

    $requestCommentTextarea.on("input", function() {
    if ($requestCommentTextarea.val() !== "") {
    $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-and-submit-translation"));
    $requestCommentSubmitButton.prop("disabled", false);
    } else {
    $requestMarkAsSolvedButton.text($requestMarkAsSolvedButton.data("solve-translation"));
    $requestCommentSubmitButton.prop("disabled", true);
    }
    });

    // Disable submit button if textarea is empty
    if ($requestCommentTextarea.val() === "") {
    $requestCommentSubmitButton.prop("disabled", true);
    }

    // Submit requests filter form in the request list page
    $("#request-status-select, #request-organization-select")
    .on("change", function() {
    search();
    });

    // Submit requests filter form in the request list page
    $("#quick-search").on("keypress", function(e) {
    if (e.which === 13) {
    search();
    }
    });

    function search() {
    window.location.search = $.param({
    query: $("#quick-search").val(),
    status: $("#request-status-select").val(),
    organization_id: $("#request-organization-select").val()
    });
    }

    function toggleNavigation(toggleElement) {
    var menu = document.getElementById("user-nav");
    var isExpanded = menu.getAttribute("aria-expanded") === "true";
    menu.setAttribute("aria-expanded", !isExpanded);
    toggleElement.setAttribute("aria-expanded", !isExpanded);
    }

    $(".header .icon-menu").on("click", function(e) {
    e.stopPropagation();
    toggleNavigation(this);
    });

    $(".header .icon-menu").on("keyup", function(e) {
    if (e.keyCode === 13) { // Enter key
    e.stopPropagation();
    toggleNavigation(this);
    }
    });

    $("#user-nav").on("keyup", function(e) {
    if (e.keyCode === 27) { // Escape key
    e.stopPropagation();
    this.setAttribute("aria-expanded", false);
    $(".header .icon-menu").attr("aria-expanded", false);
    }
    });

    if ($("#user-nav").children().length === 0) {
    $(".header .icon-menu").hide();
    }

    // Submit organization form in the request page
    $("#request-organization select").on("change", function() {
    this.form.submit();
    });

    // Toggles expanded aria to collapsible elements
    $(".collapsible-nav, .collapsible-sidebar").on("click", function(e) {
    e.stopPropagation();
    var isExpanded = this.getAttribute("aria-expanded") === "true";
    this.setAttribute("aria-expanded", !isExpanded);
    });

    //Added your code here inside thee last brackets

    if (HelpCenter.user.organizations[0].name != "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }

    // Change text 'Submit request'
    $('.submit-a-request').html('Submit a Query');


    });

     

    There is not much in the difference between the coding. I can't figure out why it won't work on the custom coding page comparing the two codes.

    Can you please assist further with this?

    I really appreciate your help and persistence to get this to work for me.

    Kind Regards,

    Anton

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    I was able to get the code to work with your custom JS so not sure where the issue is. 

    Lets try to add a script directly to your new_request_page.hbs . The script will slightly be different but is because we are adding it directly to the html page.

    Go ahead and remove the code we worked on from the JS page. Access your new_request_page.hbs which is the page when you are submitting requests. 

    Add the following script to the very bottom:

    <script>
    $(document).ready(function() {
    if ($(HelpCenter.user.organizations[0].name != "AntonTest")){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }
    });
    </script>

     

    Here is a screenshot for example (my form ids are different for my page:

     

    If you still run into an issue, feel free to post your new_request_page.hbs. Fingers crossed it works! Thank you

    0
  • Anton Van der meyden

    Hello Socorro,

    Unfortunately the script did not work on my Custom Theme or the Copenhagen Theme. It still shows the test form in the drop down.

    Here is the coded added to the Copenhagen theme:

    <div class="container-divider"></div>
    <div class="container">
    <nav class="sub-nav">
    {{breadcrumbs}}
    {{search submit=false}}
    </nav>

    <h1>
    {{t 'submit_a_request'}}
    {{#if follow_up}}
    <span class="follow-up-hint">
    {{follow_up}}
    </span>
    {{/if}}
    </h1>

    <div class="form">
    {{request_form}}
    </div>
    </div>


    <script>
    $(document).ready(function() {
    if ($(HelpCenter.user.organizations[0].name != "AntonTest")){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }
    });
    </script>

     

    Here is the code in my Custom Theme. There is alot of custom script added to this.

     

    <div class="container-divider"></div>

    <div class="container">
    <nav class="sub-nav">
    <ol class="breadcrumbs">
    <li title="{{help_center.name}}">{{#link 'help_center'}}{{help_center.name}}{{/link}}</li>
    <li title="Submit a Query">Submit a Query</li>
    </ol>

    {{search submit=false}}
    </nav>


    </p>Have you read our <a href="https://kigomarketplaceca.zendesk.com/hc/en-us/categories/360003061073-Support"> Help Center</a> articles before submitting a ticket?</p>

    <br>

    <h1>
    Submit a Query
    {{#if follow_up}}
    <span class="follow-up-hint">
    {{follow_up}}
    </span><div>

    {{/if}}
    </h1>

    <div class="form">
    {{request_form}}
    </div>
    </div>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034303873;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002789774) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360026799354;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002823894) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034573053;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002818753) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034453173;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002805233) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034356953;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002798134) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034527054;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002810974) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>
    $(document).ready(function() {
    if ($(HelpCenter.user.organizations[0].name != "AntonTest")){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }
    });
    </script>

    I could export the code from my custom theme to the Copenhagen theme as it worked on JS file on the Copenhagen theme.

    Thanks again for your help.

    Kind Regards,

    Anton

     

     

    0
  • Anton Van der meyden

    Actually I would prefer not to have to transfer the code over to the Copenhagen theme.

    Thanks.

    Anton

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    Does your custom theme not have a new request page? I was referring back to where you could add the script to your custom theme, assuming it has the request page. Really, you could add it to wherever your request page is. I am more than happy to talk through this still if you would like. Thank you.

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

     

    The code in my previous message is from the new_request_page.hbs. I just left out the tab that says new_request_page.hbs.

    Please see screenshot below of the code from my custom theme. There is a screenshot followed by text for the rest of my custom code I have added to this page. The code in my previous message was on the new_request_page.hbs.for my custom theme and Copenhagen theme.

     

     

     

     

    .

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034303873;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002789774) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360026799354;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002823894) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034573053;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002818753) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034453173;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002805233) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034356953;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002798134) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>

    $(document).ready(function() {

    var issuePickerTicketFieldID = 360034527054;
    var ticketFormID = location.search.split('ticket_form_id=')[1];
    var ticketFormTitle = $('select#request_issue_type_select > option:selected').text();

    if (ticketFormID == 360002810974) {
    $('.form-field.request_subject').hide(); // hide subject
    $('#request_subject').val(ticketFormTitle);
    $('#request_custom_fields_' + issuePickerTicketFieldID).on('change', function() {
    var issue = $(this).next('a.nesty-input').text();
    $('#request_subject').val( issue);
    });
    }

    });

    </script>

    <script>
    $(document).ready(function() {
    if ($(HelpCenter.user.organizations[0].name != "AntonTest")){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }
    });
    </script>

     

    Please assist me further in getting a resolution to this.

     

    Thank you.

     

    Kind Regards,

    Anton

     

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

     

    Just to let you know all the script that I added before your script at the bottom works as has the desired effect.

    Thanks again for your help with this.

    Kind Regards,

    Anton

     

     

     

     

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    I copied your script page as well as your new_request_page.hbs with my script and the script is still working correctly. The problem with this test is that I do not have all your organizations, forms, fields etc. At this point, I would love to continue help you but I would need to be able to see the help center to pin point what is going on.

    I don't work for or represent Zendesk in any manner, just part of their community and I am willing to help where I may.

    Feel free to message me if you want to set up some sort of skype/discord call.

    Here are some more resources for reference:

     

     

    0
  • Anton Van der meyden

    Hello Socorro,

    Would it help if I sent you the hyperlink to the help center so you could inspect the code?

    I would be happy to setup some sort of Skype call. I'm based in Ireland. 

    How will we setup the call?

    Thanks for your help.

    Kind Regards,

    Anton

     

     

    0
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

    I have gotten a bit closer to getting this to work on my custom theme.

    When I pick my custom theme and pick the role as Anonymous or End user the script code works and hides the form but when I open the link to the Help Center in a browser the form reappears again. The strange thing is picking End user or Anonymous here should be the equivalent to opening the Help Center in a browser as an end user. 

    See screenshot below of the form hidden when I pick Anonymous,.

    Any ideas what might cause this to happen?

     

    Kind Regards,

    Anton

     

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    I agree in that if you open a browser and you are not logged in with an account that has the AntonTest organization, I would expect the form not be visible just as you tested in the preview. And if you create a separate end user account, just making sure the organization is not defaulted to AntonTest.

    Depending on the browser, it could potentially not run scripts or something like that but i would expect no scripts to run, not just the one. But again, you ran it in preview so im not 100% why the behavior would change.

    Make sure your custom theme is your live one when testing in browser :)

    Being able to access and inspect the code for any errors etc would get it us closer to the source. Again, don't feel obligated at all as I want to respect your help center. I did send a request to what may be your personal skype, feel free to add socco87 im available now if needed

    0
  • Anton Van der meyden

    Hello Socorro,

    I just messaged you on Skype if your free now for a chat?

    Kind Regards,

    Anton

    0
  • Socorro Fernandez
    Community Moderator

    Hi Anton,

    Thank you for connecting with me in skype!

    We found out that the script was erroring when a user did not have any organization assigned to them which is true for anonymous users or end users with no organization assigned to them. I believe I have finally found the script that will work for you. The code basically reads If your organization value is null or if it does not = AntonTest , then remove the forms based on the values. This should continue to work on your Script page:

    if (HelpCenter.user.organizations[0] == null || HelpCenter.user.organizations[0].name != "AntonTest"){
    $('#request_issue_type_select option[value="360002822914"]').remove();
    $('.nesty-panel').on('DOMNodeInserted', function(e){ $(this).children('ul').children().remove('#360002822914');
    });
    }

     

    This should solution for the error and work as you needed Anton.

    For anyone else following, I have bolded the areas you would want to update, organization name and the custom id form you would want to remove from the dropdown list.

    Please let me know if you run into any issues Anton. Thank you.

    1
  • Anton Van der meyden

    Hello Socorro,

    Socorro Fernandez

    Thank you for taking the time to Skype with me.

    The code works. Thank you very much for helping me with this. 

    I would now like to make any other form not be visible to AntonTest. Meaning when I log in as AntonTest Org the only form I see will be the AntonTest form, all other forms will be removed when I'm logged in.

     

    I added the below code to your code but it did not work.

     

     if (HelpCenter.user.organizations[c].name != "AntonTest"){
    $("#360002818973").remove();
    }

     

    I believe this should be possible using if statements. Can you please assist me with this?

    Kind Regards,

    Anton
     

    0
  • Anton Van der meyden

    I also tried this with the if statement as:

     if (HelpCenter.user.organizations[c].name == "AntonTest"){
    $("#360002818973").remove();
    }

    Meaning if the the organization is Antontest remove this form but id does not work.

     

    Kind Regards,

    Anton

    0
  • Anton Van der meyden

    Hello Socorro,

    I got this to work using if statements.

    Thanks again for your help.

    Kind Regards,

    Anton

    0

Please sign in to leave a comment.

Powered by Zendesk