Agent Desktop

Get Involved. Join the Conversation.

Topic

    Laura Walker
    show a report column based on a conditionAnswered
    Topic posted April 4, 2019 by Laura WalkerBlue Ribbon: 750+ Points 
    99 Views, 10 Comments
    Title:
    show a report column based on a condition
    Summary:
    Show a report Column based on a queue value
    Content:

    Hi all,

    In the incident queue report, we are trying to display the 'created by' column only for a certain queue value.  So when the user selects that particular queue from slice queue list, then the column should show, else don't show when other queue is selected from the slice list.

    I did some reading about how to accomplish this, but I was not successful.  I read Answer ID 2284   |   Last Review Date 12/17/2018.  I am just trying to learn php and so what I attempted to do is wrong, see attached image.

    Is hiding/showing a column accomplished only through a script and if that is the case could you direct me to a good site to read about it or do you have some suggestions?

    Is there other way to hide/show a report column through the agent desktop?

    Thank you,

    Laura

     

    Version:
    AGENT DESKTOP 18B
    Image:

    Best Comment

    Sebastiaan Draaisma

    Just paste the text here from the private message :-)

    For the custom script:

    Because filter and variable values ($params) are only available within the initial state, we need to capture the user input into a global variable. For this we use the following code into the Initialization tab

    global $filtersAndVariables;

    $filtersAndVariables = $params;

     

    Columns and headers can to my knowledge only be manipulated inside the Headers tab. Inside this tab we will read the user input for the runtime filter and do something with it. To do this we first have to call the global variable into our Headers tab. After we have done this we can work with the user input. In this example the queue that should show the column has id 6. We create an IF statement where we retrieve the filter value ["val"] (which is inside an array) and say IF ["val"] does not equal 6, {Do this}. Within the curly brackets (the do this section) we use the PHP array_splice function to remove an item from an array. Columns inside a report are stored inside an array called $headers. As items in an array always start from 0, the third column is the second item in the array (0,1,2). In the array_splice (which you could compare with a substring function) we specify to start removing at item 2 and specify the length (1 item). This all means that only the 2nd item (3rd column) will be removed.

     

    global $filtersAndVariables;

    // In this case 6 is the queue id where you want to show the column, if it's not the right queue it will hide the column

    if ($filtersAndVariables["search_args"]["search_field0"]["val"] != 6){

    array_splice($headers, 2, 1); // Remove the column Created by agent

    }

     

    Unfortunately I have not found a way to add the column back into the array once it has been removed. I believe this is as intended as the report runs in a sequence. It is the same when removing rows from your report. After removing them you are unable to put them back in.

    1. Initialization
    2. Headers
    3. Process
    4. Finish

     

    Now…. :-)

    While this all works fine with a filter, I do not know if this can be done with a slice report.

     

    The only alternative is then to use masking where you use the following expression: if(incidents.queue_id.id=6,incidents.created_by,'')

    The single quotes will create an empty string if the queue id is not equal to 6

    Through column formatting (right click on the column) you can choose NULL values to show up as blank

    The column header would still be there but this is not required. You could stitch the text into your queue column by using:

    incidents.queue_id||' id='||incidents.queue_id.id||if(incidents.queue_id.id=6,'    Created by '||incidents.created_by,'')

     

    This would make your report look like this

    Comments Are Closed

     

    • Sebastiaan Draaisma

      Hi Laura.

      It may be possible through an add-in (I have no experience with add-ins but this would also require coding).
      It can only be done through code (custom script or maybe an add-in).

      The custom script to manipulate columns has to be entered in the Headers tab.
      See attached report example that will change column names and removes the 3rd column from the array.

      The code used is:

      // Renaming columns
      $headers[0] = 'Ref no.';
      $headers[1] = 'Q';
      $headers[2] = 'Created by';

      // PHP function to remove an item (column) from an array
      array_splice($headers, 2, 1); // This starts removing at item [2] and only 1 long (so one item only)

      It is based on the PHP array_splice function.

    • Ajay Yadav

      Hi Laura,

      i think we can do this by Transaction Table, let me make a sample report and send it you.

    • Ajay Yadav

      Hi Laura,

      i made this report with Incident table so it will give current queue status of the incident. if you need historical data then you can think of Transaction table. 

      • Laura Walker

        Ajay,

        Thank you so much for your help, I am not able to open the .xml file so I am not able to look at the content.  The concept sounds interesting to see and try.   i

        Thank you,

        Laura

         

    • Sebastiaan Draaisma

      While masking (as Ajay points out) is an option. It does not hide the column. If hiding the column is required see attached report based on $params that will read the filter value and places this into a global variable which is then comparred to the queue id. If there is a match it will show the column. If there is no match it will hide the column.

      I'm not sure if this will work with a slice as the data you want to use may be loading in a different sequence

      1. Initialisation
      2. Headers
      3. Process
      4. Finish

      If you are new to PHP this may be a little too advanced but if you have no deadline then you are able to experiment, test and learn through trial and error :-)
      (I'm no PHP expert myself)

      Initialisation

      global $filtersAndVariables;
      $filtersAndVariables = $params;

      Headers

      global $filtersAndVariables;

      // In this case 6 is the queue id where you want to show the column, if it's not the right queue it will hide the column
      if ($filtersAndVariables["search_args"]["search_field0"]["val"] != 6){
      array_splice($headers, 2, 1); // Remove the column Created by agent
      }

    • Laura Walker

      Hi Sebastiaan,

      I tried what you suggested on a test report that I created and it work.  The issue is that when I tried it on the report that I need to change I got a digit out of range message.  I think it has to do with a hidden column, but I will continue working on it since I don't have to turn in this change right away.

      I was not able to open the .xml document, so I could not see the contents.

      Thank you for your help,

      Laura

       

    • Sebastiaan Draaisma

      Send me a private message with your email address and I will send the report by mail with some screenshots. The out of range digit is something I have seen before. Usually related to a long integer.

      See: Sum of integers in report column out of integer range

    • Sebastiaan Draaisma

      Just paste the text here from the private message :-)

      For the custom script:

      Because filter and variable values ($params) are only available within the initial state, we need to capture the user input into a global variable. For this we use the following code into the Initialization tab

      global $filtersAndVariables;

      $filtersAndVariables = $params;

       

      Columns and headers can to my knowledge only be manipulated inside the Headers tab. Inside this tab we will read the user input for the runtime filter and do something with it. To do this we first have to call the global variable into our Headers tab. After we have done this we can work with the user input. In this example the queue that should show the column has id 6. We create an IF statement where we retrieve the filter value ["val"] (which is inside an array) and say IF ["val"] does not equal 6, {Do this}. Within the curly brackets (the do this section) we use the PHP array_splice function to remove an item from an array. Columns inside a report are stored inside an array called $headers. As items in an array always start from 0, the third column is the second item in the array (0,1,2). In the array_splice (which you could compare with a substring function) we specify to start removing at item 2 and specify the length (1 item). This all means that only the 2nd item (3rd column) will be removed.

       

      global $filtersAndVariables;

      // In this case 6 is the queue id where you want to show the column, if it's not the right queue it will hide the column

      if ($filtersAndVariables["search_args"]["search_field0"]["val"] != 6){

      array_splice($headers, 2, 1); // Remove the column Created by agent

      }

       

      Unfortunately I have not found a way to add the column back into the array once it has been removed. I believe this is as intended as the report runs in a sequence. It is the same when removing rows from your report. After removing them you are unable to put them back in.

      1. Initialization
      2. Headers
      3. Process
      4. Finish

       

      Now…. :-)

      While this all works fine with a filter, I do not know if this can be done with a slice report.

       

      The only alternative is then to use masking where you use the following expression: if(incidents.queue_id.id=6,incidents.created_by,'')

      The single quotes will create an empty string if the queue id is not equal to 6

      Through column formatting (right click on the column) you can choose NULL values to show up as blank

      The column header would still be there but this is not required. You could stitch the text into your queue column by using:

      incidents.queue_id||' id='||incidents.queue_id.id||if(incidents.queue_id.id=6,'    Created by '||incidents.created_by,'')

       

      This would make your report look like this

    • Laura Walker

      Sebasteaan, Thank you so much, I tried the last option and it works!