Create Request On Behalf Of - Radio Buttons and Text Change

Nicholas_VelichNicholas_Velich Cireson Consultant Ninja IT Monkey ✭✭✭✭
Original thread here: https://community.cireson.com/discussion/comment/5767

Summary of customization:

(1) Rather than allowing the analyst to immediately type in the user picker, they must first choose that they want to create on behalf of:



(2) Once they pick Yes, the picker appears as usual; however, notice the "placeholder text" now reads "Search for User" instead of the default "Choose One..."



The code used to accomplish this is attached. It would need to be copied into your custom.js file (ideally using getScript or the loadScript method). If you don't want the feature in (1) above, you can comment out or delete lines 6-21. If you want to change the placeholder text, that can be done on line 24.

Two other tidbits outside of the attached code:

(3) The actual "Create Request On Behalf Of" text can be changed in the localization section of the portal. The key you would override is "CreateRequestonbehalfof." Note that the "Choose One..." change could also be done from the localization section using the "ChooseOne' key; however, changes to localizations are Portal-wide, which might not be desirable.

(4) Changing what results appear once you start typing can be configured in the Admin Settings portion of the Portal. The keys you would modify in this case are "UserQuery" and "GroupQuery." If there is a particular attribute unique to all your Distribution Groups, you can add them to these search filter settings to omit them.

Comments

  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    edited March 2017
    One thing that should be added to the code above is a check to see that the user has the right to create tickets on behalf of other users. If they don't, then the control which the code is looking for will not be present on the form, and the page will not load.

    This code should be added near the start of the function:
    $(window).load(function () {
           if (!session.user.Security.CreateOnBehalf) return;

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    The original script did make sure you were on a URL that checked for URL location. However to meet the request added both clauses to the if statement. 

    $(window).load(function () {
        if ((document.URL.indexOf("ServiceCatalog/RequestOffering") === -1) || (!session.user.Security.CreateOnBehalf)) { //Only worry about request offering forms
            return; 
        }

  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    Hi Brian,

    I didn't mean to replace the RequestOffering condition, but you can combine the two statements as you have done.
  • Tim_ShackletonTim_Shackleton Customer IT Monkey ✭
    I'm having issues with this script, in that I don't see any of the changes to the field.  I've tried placing the script directly in custom.js as well as in a separate file that is called via $.getScript.

    What could I be doing wrong?

  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    The most likely explanation is that there is a syntax error in the custom.js file which is stopping the code from executing. Open developer tools in the browser and check for errors on the console tab.
  • Tim_ShackletonTim_Shackleton Customer IT Monkey ✭
    edited April 2017
    The most likely explanation is that there is a syntax error in the custom.js file which is stopping the code from executing. Open developer tools in the browser and check for errors on the console tab.

    There is a syntax error in the original upload at the top of the page.  Line 24 is missing a semicolon.
  • Brad_HayesBrad_Hayes Member IT Monkey ✭

    I made some changes to the script and changed the radio buttons to a toggle.

    /*************************************/
    /*** Request on Behalf of Toggle ***/
    /*************************************/

    // Only load code on Request Offering page
    $(window).load(function() {
     if (document.URL.indexOf("ServiceCatalog/RequestOffering") === -1) {
      if (!session.user.Security.CreateOnBehalf) return;
     }
     
     // Hide create request on behalf of picker by default
     $('.control-label:contains("' + localization.CreateRequestonbehalfof + '")').parent().find('.two-action-input-group').hide();  
     
     // Create toggle and append after the picker
     var toggler_CBR = $('<button class="toggler">Switch...</button>');
     toggler_CBR.appendTo('label.control-label:contains("' + localization.CreateRequestonbehalfof + '")');

     // Set toggle function (Show Hide)
     $("#button_CRB").button()
     $("button.toggler").click(function() {
      $Switch = $(this);
      $Switch.toggleClass('off');
      if ($Switch.is(".off")) {
       $('.control-label:contains("' + localization.CreateRequestonbehalfof + '")').parent().find('.two-action-input-group').show();
      }
      else {
       $('.control-label:contains("' + localization.CreateRequestonbehalfof + '")').parent().find('.two-action-input-group').hide();
      }
     });
      
     // Change the placeholder text in the picker
     $('.control-label:contains("' + localization.CreateRequestonbehalfof + '")').parent().find('.k-input.search-combo').attr("placeholder", "Search for User")
    });

  • Joshua_WalkerJoshua_Walker Customer IT Monkey ✭
    Will the "Yes" and "No" text follow the localization if we switch languages? i figured the answer is no since it seems to be hardcoded into the script. We use the portal in english and french so any customization i want to apply, i have to make sure i can support it in both languages.
  • Nicholas_VelichNicholas_Velich Cireson Consultant Ninja IT Monkey ✭✭✭✭
    Hi @Joshua_Walker

    The script as provided above is only partially localized, but it would be a fairly simple update to localize it the rest of the way. Note in the code that the text for "Create on behalf of" is referenced via localization key, not hard-coded text, i.e. - localization.CreateRequestonbehalfof. The same concept would need to be applied for "Yes," "No," and any other hard-coded text within the code.

    You can view all Portal localizations, override localizations or add new localizations by clicking your name in the top-right, then selecting "Localizations." Either way, localizations are all referenced in code via localization.localizationkey.
  • Mark_GearyMark_Geary Customer IT Monkey ✭
    Is there any way that we can show this for the end users?
  • damon_mulligandamon_mulligan Cireson Consultant Advanced IT Monkey ✭✭✭
    If you place "Domain Users" in the Admin Settings > Setting Items > CreateOnBehalfGroup
    You have to make sure the "Domain Users" AD Group is in your SCSM Users CI, then make sure it is populated in the Cache for the Portal.
  • Steve_ClarkeSteve_Clarke Customer Adept IT Monkey ✭✭
    Hi @Nicholas_Velich

    The rendering is a little messed up in the latest version of the portal. Is it possible to get an updated version? Great modification btw :)

    Thanks
  • Nick_FlintNick_Flint Customer Adept IT Monkey ✭✭
    @Steve_Clarke

    Try adding this to your custom.css:

    /*Fix Create on Behalf of Button Rendering*/
    input#behalfdisabled, input#behalfenabled
    {
        width: 3%;
    }

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    @Nick_Flint
    That did the trick for my environment, Thanks
  • Steve_ClarkeSteve_Clarke Customer Adept IT Monkey ✭✭
    Awesome, thank you @Nick_Flint.
Sign In or Register to comment.