Create custom dropdown field for new tickets.

English! place to talk about development, programming and coding
Post Reply
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Create custom dropdown field for new tickets.

Post by Lubomirsb »

I am new to otrs and i read some articles but i couldnt find a solution to my problem. So here it is. I need a custom dropdown field in new ticket (lets say new phone ticket) that is populated with data. I will give an example:
I have a Company lets name it MyCompany( id=MyCompany1 )
I have 3 customers with the same ID (MyCompany1)
usernames-> Customer1login ,Customer2login .... etc
firstnames-> Customer1, Customer2,Customer3
I need when I create a ticket and when I insert the customer this dropdowen field to be populated with the firstnames of all customers in that company.
If i Choose Customer1login from Company1 my field will be populated with Customer1, Customer2,Customer3.

So far i did this:
I found a similar problem here-> viewtopic.php?f=60&t=17033

So i decided to do it that way. I have created a dynamic field , i have the script , its working, the data its populated (its not dependent yet on the customer i dont know how yet)
here is my ajax in AgentTicketPhone.dtl

<script type="text/javascript">//<![CDATA[
$.ajax({
type: "get",
url: "extdata.pl",
dataType: "html",
success: function(html){
$("#DynamicField_Test").append(html).unbind("change");
}
});
//]]></script>

The problem is that when i choose something from the form , lets say change the priority my dropdown field data its gone .

This is the script which causes the problem i think

<script type="text/javascript">//<![CDATA[
$('#PriorityID').bind('change', function (Event) {
Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'PriorityID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'NextStateID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID',$Data{"DynamicFieldNamesStrg"}, 'To', 'Cc', 'Bcc']);
});
//]]> </script>

I really need some help here. I am stuck for 3 days already. Thanks in advance and sorry for my bad english !
OTRS 3.3.4 ,Centos 6.5
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Re: Create custom dropdown field for new tickets.

Post by Lubomirsb »

Or if someone can tell me how to run my script after this script

<script type="text/javascript">//<![CDATA[
$('#PriorityID').bind('change', function (Event) {
Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'PriorityID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'NextStateID', 'ServiceID', 'SLAID', 'SignKeyID', 'CryptKeyID',$Data{"DynamicFieldNamesStrg"}, 'To', 'Cc', 'Bcc']);
});
//]]> </script>
OTRS 3.3.4 ,Centos 6.5
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Create custom dropdown field for new tickets.

Post by reneeb »

I did something similar for a customer. There I added those lines to AgentTicketPhone.pm and AgentTicketEmail.pm:

Code: Select all

            my $Excluded = $Self->{ConfigObject}->Get( 'Customer::ExcludeDynamicFieldsFromJS' ) || [];
            if ( grep{ $Field eq $_ }@{ $Excluded } ) {
                next FIELD;
            }
Those lines were added in the inner for loop of this original code:

Code: Select all

    # create a string with the quoted dynamic field names separated by a commas
    if ( IsArrayRefWithData($DynamicFieldNames) ) {
        my $FirstItem = 1;
        FIELD:
        for my $Field ( @{$DynamicFieldNames} ) {
            if ($FirstItem) {
                $FirstItem = 0;
            }
            else {
                $Param{DynamicFieldNamesStrg} .= ', ';
            }
            $Param{DynamicFieldNamesStrg} .= "'" . $Field . "'";
        }
    }
So it looks like

Code: Select all

    # create a string with the quoted dynamic field names separated by a commas
    if ( IsArrayRefWithData($DynamicFieldNames) ) {
        my $FirstItem = 1;
        FIELD:
        for my $Field ( @{$DynamicFieldNames} ) {
# ---
# Perl-Services.de
# ---
            my $Excluded = $Self->{ConfigObject}->Get( 'Customer::ExcludeDynamicFieldsFromJS' ) || [];
            if ( grep{ $Field eq $_ }@{ $Excluded } ) {
                next FIELD;
            }
# ---

            if ($FirstItem) {
                $FirstItem = 0;
            }
            else {
                $Param{DynamicFieldNamesStrg} .= ', ';
            }
            $Param{DynamicFieldNamesStrg} .= "'" . $Field . "'";
        }
    }
And the config options looks like (in Kernel/Config/Files/PerlServices.xml):

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<otrs_config version="1.0" init="Application">
    <ConfigItem Name="Customer::ExcludeDynamicFieldsFromJS" Required="0" Valid="1">
        <Description Translatable="1">Dynamic Fields listed here are not updated with the AJAX calls in new ticket masks.</Description>
        <Group>Customer</Group>
        <SubGroup>Core</SubGroup>
        <Setting>
            <Array>
                <Item>DynamicField_TicketFreeText1</Item>
                <Item>DynamicField_TicketFreeText2</Item>
            </Array>
        </Setting>
    </ConfigItem>
</otrs_config>
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Re: Create custom dropdown field for new tickets.

Post by Lubomirsb »

Thank you for the answer. But i dont have PerlServices.xml in that directory. I must create it or ? Sorry i am new to otrs and i am trying to do something that is difficult for me at that time.

By the way I fixed the problem where my values from the dropdown are gone. Now the question is how to pass a parameter to extdata.pl in the SQL.
OTRS 3.3.4 ,Centos 6.5
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Create custom dropdown field for new tickets.

Post by reneeb »

Lubomirsb wrote:Thank you for the answer. But i dont have PerlServices.xml in that directory. I must create it or ?
Yes
Lubomirsb wrote:By the way I fixed the problem where my values from the dropdown are gone.
Can you share your wisdom?
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Re: Create custom dropdown field for new tickets.

Post by Lubomirsb »

Its just a temporary solution , I really dont know where the problem is. I just modified the dynamic field
Added this

Code: Select all

                    <div class="Row Row_DynamicField_$QData{"Name"}">
                        $Data{"Label"}
                        <div class="Field">
                            $Data{"Field"}
				<a href="#" id="OwnerSelectionGetAll2" class="GetAllAJAX" title="$Text{"Get all"}">$Text{"Get all"}</a> //  I added this line 
                        </div>
                        <div class="Clear"></div>
                    </div>

and my Ajax is now like this

Code: Select all

$('#OwnerSelectionGetAll2').bind('click', function (Event) {
        $('#OwnerAll').val('1'); // Needed? Why?
        Core.AJAX.FormUpdate($('#NewPhoneTicket'), 'AJAXUpdate', 'OwnerAll', ['NewUserID'], function() {
            $('#NewUserID').focus();
$.ajax({
  type: "get",
  url: "extdata.pl", 
  dataType: "html",
  success: function(html){
  	$("#DynamicField_Test").append(html).unbind("change");
  }
});


       });
        return false;
    });
So for example when i change lets say the priority of the ticket my values from the dynamic field are gone BUT when i press the refresh (get all) button in the right the values are back and i can select it.
OTRS 3.3.4 ,Centos 6.5
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Re: Create custom dropdown field for new tickets.

Post by Lubomirsb »

Can you explane me what your code does ? Because i am trying it right now and i dont get it. Maybe e little deeper explanation will be great ! Thanks.
OTRS 3.3.4 ,Centos 6.5
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Re: Create custom dropdown field for new tickets.

Post by Lubomirsb »

Ok another question. When i try to submit the ticket it says "One or more errors occurred!" .
This happens when i choose one of the added with ajax values.
How to save the dynamic field value ?


btw this is what i see with firebug

Code: Select all

<div class="Row Row_DynamicField_Test">
<label id="LabelDynamicField_Test" class="LabelError" for="DynamicField_Test"> Test: </label>
<div class="Field">
<select id="DynamicField_Test" class="DynamicFieldText ServerError Error" size="1" name="DynamicField_Test" aria-invalid="true">
<option value="" selected="">-</option>
<option value="test">test</option>  ->>>>>>> This is value inserted in OTRS
<option value="test2">test2</option> ->>>>> This is value filled with AJAX (if i choose this the error shows.)

</select>
<div id="DynamicField_TestServerError" class="TooltipErrorMessage">
<a id="OwnerSelectionGetAll2" class="GetAllAJAX" title="Get all" href="#">Get all</a>
</div>
<div class="Clear"></div>
</div>
Please help :(
OTRS 3.3.4 ,Centos 6.5
Post Reply