How to add a custom column to OTRS ticket view (dashboard) - perl

I've been trying to append some more data to an OTRS ticket (newest version). And I have managed to get the information in the ticket data alright, however, I do not know how to access it in the view. Most data seems to be parsed through via $QData/$Data, however, all I get when I print my variable is 16/12.
%CustomerCompanyName = $Self->{CustomerCompanyObject}->CustomerCompanyGet( CustomerID => $Ticket{CustomerID} );
#}
$Ticket{CustomerCompanyName} = \%CustomerCompanyName;
And I want to access it in the dtl AgentDashboardTicketGeneric.dtl, however, $Data{"CustomerCompanyName"} is empty. I've managed to get the hash or 16/12 out. Again, in the variable $Ticket we've managed to dump the variable and see the data is actually in there (without actually being able to access it, we can't figure out which data type it is and have tried all possible ways we could think of).
Edit: I figured it out. It worked with Johannes solution, however, the value of the column in the SysConfig had to be 2, and not 1.

you can access all Ticket Data through the User Interface. In every widget, in the top right corner you can access the settings and remove, add, sort columns.
If you need the Customer Company data, which are not bound to the ticket-data, then you need to modify / extend the given module (Kernel::Output::HTML::DashboardTicketGeneric). Thats the reason why $Data{"CustomerCompanyName"} is empty, because the customer company stuff is not loaded there.
IMHO you don't need to modify the dtl. Add the new column in the sysconfig:
HTTP://OTRSHOST/otrs/index.pl?Action=AdminSysConfig;Subaction=Edit;SysConfigSubGroup=Frontend%3A%3AAgent%3A%3ADashboard;SysConfigGroup=Ticket
Add the new Column "CompanyName" to every widgets DefaultColumns.
(Hint: here you can also add DynamicFields using DynamicField_XXX)
Then modify the Code in DashboardTicketGeneric.pm
First: add the module (around L:21)
use Kernel::System::CustomerCompany;
after that initiate the module (after CustomerUserObject around L: 44)
$Self->{CustomerCompanyObject} = Kernel::System::CustomerCompany->new(%Param);
Then add the logic to the module (around L: 1414 - after the customer name block:
elsif ( $Column eq 'CompanyName' ) {
# get customer company name
my %CompanyData;
if ( $Ticket{CustomerID} ) {
%CompanyData = $Self->{CustomerCompanyObject}->CustomerCompanyGet(
CustomerID => $Ticket{CustomerID},
);
}
$DataValue = $CompanyData{CustomerCompanyName};
}
Then delete the cache (..bin/otrs.DeleteCache.pl), because widgets use caching and your changes won't apply fast enough ;)
Add the column to your widget (top right corner in the widget -> Settings) and you should be fine.
Update: place the "new Module" in the custom folder
Custom/Kernel/Output/HTML/DashboardTicketGeneric.pm
regards
Johannes

Related

Auto complete in text field in odoo

I would like to select a customer from the select box by start typing its phone number.
How can I do that?
I have seen some are using name_search method.But still i am confused how to use it in both front end and back end.
Or is there any other solution for this.
Override the name_search method of your model and the domain you want on the args variable. Take a look at addons/account/account.py around line 595 args += [('type', '=', type)] for a concrete implementation. Make sure that you return the appropriate data structure as documented in the method's docstring at openerp/models.py.
For Auto complete in odoo. It provides suggestion only in case of using Many2one field in any module.
If you want to show suggestion and autocomplete. Create a model to store the mobile numbers and then use that particular model as foreign key in existing model.
That will do for you.

Retrieving two records with the same name

I have to get two different names pulled from this query, the Account Name and the Opportunity Name. Both are called "Name" under each object.
I am able to use a query to retrieve both of them, but I am unable to decipher between the two in order to actually echo/print or use them.
My Query is:
$query = "SELECT Name,Opportunity.Account.Name from Opportunity ";
$response = $mySforceConnection->query($query);
foreach ($response->records as $record) {
echo $record->Name ."<br/>\n";
//echo $record->Opportunity.Account.Name ."<br/>\n";
echo "<br/>\n"; }
The only Name that is displayed is the opportunity Name (when trying different methods, I know the code above will only echo that)
I have made two seperate queries one from account and one from opportunity to ensure both are infact different things, and they are.
I have attempted to echo two "Name" records, both are just the opportunity name it doesn't recognize the account name.
And obviously what is commented out above as "Opportunity.Account.Name" isn't echoing the result, i am recieving an error instead.
I know using an alias is not supported in salesforce so that obviously didn't and won't work, by that I mean trying to do this:
Select Name as OppName
I am unable to find a different way to echo the records, I have done a lot of googling on the subject. Any help would be appreciated or a point in the right direction.
In my schema there is no Name field in the Opportunity object. There is Account Name and it is a lookup on Account Name in the Account object. You can view the schema builder by going to Setup > Schema Builder (it is under App Setup).
To be honest, I don't know why this worked. I'm new to SOAP and Salesforce, so I was just trying different things to get it working. But if anyone else has this problem, this is how I fixed it.
I displayed the account name by using this to echo it:
echo $record->Account->Name ;
The query is still the same as in the question.

Add ‘subscription_date’ and ‘user_ip_address’ fields for Newsletter Subscriber and show it in admin panel in Magento

I want to add two custom fields for newsletter subscriber at which date customer subscribed and its ip address:
1) I had added two columns in ‘newsletter_subscriber’ table.
How this can be achieved?
In the file app/code/core/Mage/Newsletter/Model/Subscriber.php
I found the the functions like:
$this->setSubscriberEmail($email);
$this->setStoreId(Mage::app()->getStore()->getId());
$this->setCustomerId(0);
But i did not found its code.
I think I also save data like that but how it will be possible ? where I have to define and declare code for the function like $this->seSubscriptionDate();
And how to display in Admin panel under Newsletter->Newsletter Subscriber ?
I had not find the solution or help from any person.
I bang my head and find the solution its very simple hope in future may some one’s time save by this post:
1) Add columns in the table “newsletter_subscriber” say in my case “subscription_date” and “sub_ip_address”
2) Add following two lines in the file # two places
app\code\core\Mage\Newsletter\Model\Subscriber.php
**$this->setSubscriptionDate(date("d-m-Y"));
**$this->setSubIpAddress($_SERVER['REMOTE_ADDR']);
One place: in the function: public function subscribe($email)
Before: $this->save();
Second place: in the function: public function subscribeCustomer($customer)
Before: $this->save();
Now data will be added in the table
Now to show in admin panel
1) Open the file app\code\core\Mage\Adminhtml\Block\Newsletter\Subscriber\Grid.php
Just add two required columns in it like
$this->addColumn('subscription_date', array(
'header' => Mage::helper('newsletter')->__('Subscription Date'),
'index' => 'subscription_date',
'default' => '----'
));
$this->addColumn('sub_ip_address', array(
'header' => Mage::helper('newsletter')->__('IP Address'),
'index' => 'sub_ip_address',
'default' => '----'
));
Now finish.
** This is the point where I spent my time and at the end I added this function on hit and trieal basis but it works.
Someone from Core magento team plz explain why this {setSubscriptionDate()}function work ? I had not declared anybody of this function.
It seems it shows intellisense to detect table field?
I also had the similar problem. However, in my case I am supposed to add a "country" and "gender" field in the newsletter form. So, on digging into the core for hours I figured this out. Below is the explaination:
In the app/design/frontend//default/template/newsletter/subscribe.phtml,
the form has getFormActionUrl() ?> in its action field. This referes to app/code/core/Mage/Newsletter/Block/Subscribe.php
The $this object used in the subscirbe.phtml file referes to this class (i.e. Mage_Newsletter_Block_Subscribe) and thus $this->getFormActionUrl() in the subscribe.phtml file refers to the function getFormActionUrl() of this class.
Now, this getFormActionUrl() is returning a method $this->getUrl('newsletter/subscriber/new', array('_secure' => true)) which belongs to its parent Mage_Core_Block_Template (I mean the method getURL()). This part is not improtant to us.
See the parameter passed to the getURL() function which is newsletter/subscriber/new
The first part "newsletter" is the module name (app/code/code/Mage/newsletter), the second part "subscriber" is the controller name (app/code/code/Mage/newsletter/controllers/SubscriberController) and the third part "new" is the method newAction in the controller SubscriberController.
Controller names are suffixed with Controller and function names are suffixed by Action. (Thanks to Phalcon framework to help understand this)
Now in the newAction() method you can see that by default, only the email is being posted
as
$email = (string) $this->getRequest()->getPost('email');
What I did was, I cloned the subscribe.phtml template with a name custom-newsletter.phtml and add two fields with name "country" and "gender". Then added the following lines in the newAction():
$country = (string) $this->getRequest()->getPost('country');
$gender = (string) $this->getRequest()->getPost('gender');
Now at line number 67 of the SubscriberController (inside the newAction() method) there is a code :
$status = Mage::getModel('newsletter/subscriber')->subscribe($email);
This line is calling the subscribe method of app/code/code/Mage/newsletter/Model/Subscriber.php and is passing the $email that is posted from newsletter form into it. I modified the line as:
$status = Mage::getModel('newsletter/subscriber')->subscribe($email,$country,$gender);
Now, I have to edit the app/code/code/Mage/newsletter/Model/Subscriber.php
When we talk about Models, we are talking about the database table the Model refers to. The model name is Subscriber and it belongs to module Newsletter so, the database table that this model affects is newsletter_subscriber
From this part on #Hassan Ali Sshahzad's question will be answered.
I added two new columns there with the name: subscriber_country and subscriber_gender.
Now, Magento' system automatically makes available a getter and a setter function to these columns with the following name:
function getSubscriberCountry(){}
function setSubscriberCountry($country_name){}
So, all I had to do in the model was:
Edit the method subscribe($email) to subscribe($email,$country,$gender)
add the following code in the subscribe($email,$country,$gender) function right before the try statement as follows:
$this->setSubscriberCountry($country);
$this->setSubscriberGender($gender);
try{
$this->save()
Hassan's method played a key role in my understanding of the MVC of Magento so its a return from my side.

Manipulating form input values after submission causes multiple instances

I'm building a form with Yii that updates two models at once.
The form takes the inputs for each model as $modelA and $modelB and then handles them separately as described here http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/
This is all good. The difference I have to the example is that $modelA (documents) has to be saved and its ID retrieved and then $modelB has to be saved including the ID from $model A as they are related.
There's an additional twist that $modelB has a file which needs to be saved.
My action code is as follows:
if(isset($_POST['Documents'], $_POST['DocumentVersions']))
{
$modelA->attributes=$_POST['Documents'];
$modelB->attributes=$_POST['DocumentVersions'];
$valid=$modelA->validate();
$valid=$modelB->validate() && $valid;
if($valid)
{
$modelA->save(false); // don't validate as we validated above.
$newdoc = $modelA->primaryKey; // get the ID of the document just created
$modelB->document_id = $newdoc; // set the Document_id of the DocumentVersions to be $newdoc
// todo: set the filename to some long hash
$modelB->file=CUploadedFile::getInstance($modelB,'file');
// finish set filename
$modelB->save(false);
if($modelB->save()) {
$modelB->file->saveAs(Yii::getPathOfAlias('webroot').'/uploads/'.$modelB->file);
}
$this->redirect(array('projects/myprojects','id'=>$_POST['project_id']));
}
}
ELSE {
$this->render('create',array(
'modelA'=>$modelA,
'modelB'=>$modelB,
'parent'=>$id,
'userid'=>$userid,
'categories'=>$categoriesList
));
}
You can see that I push the new values for 'file' and 'document_id' into $modelB. What this all works no problem, but... each time I push one of these values into $modelB I seem to get an new instance of $modelA. So the net result, I get 3 new documents, and 1 new version. The new version is all linked up correctly, but the other two documents are just straight duplicates.
I've tested removing the $modelB update steps, and sure enough, for each one removed a copy of $modelA is removed (or at least the resulting database entry).
I've no idea how to prevent this.
UPDATE....
As I put in a comment below, further testing shows the number of instances of $modelA depends on how many times the form has been submitted. Even if other pages/views are accessed in the meantime, if the form is resubmitted within a short period of time, each time I get an extra entry in the database. If this was due to some form of persistence, then I'd expect to get an extra copy of the PREVIOUS model, not multiples of the current one. So I suspect something in the way its saving, like there is some counter that's incrementing, but I've no idea where to look for this, or how to zero it each time.
Some help would be much appreciated.
thanks
JMB
OK, I had Ajax validation set to true. This was calling the create action and inserting entries. I don't fully get this, or how I could use ajax validation if I really wanted to without this effect, but... at least the two model insert with relationship works.
Thanks for the comments.
cheers
JMB

MS Access implenting hyperlink like behavior for records to switch between forms

I'm currently working on a Database which requires the following functionality:
For example given a specific project, I have a series of structures which belong to that project, which are displayed in a datasheet view on the project form. I am attempting to allow the user to on double click to navigate to that specific structure which is displayed on another form. Currently I am using filters to implement this behavior, however, this results in the filter being left on, and when I manually turn off the filter, the form I switch to returns back to the first entry.
I am using the current code on the datasheet:
Private Sub struct_name_DblClick(Cancel As Integer)
LookupValue = Me.struct_ID
Form_frm_control.pg_structure.SetFocus
Form_frm_control.subform_structure.Form.Filter = "struct_ID = " & LookupValue
Form_frm_control.subform_structure.Form.FilterOn = True
End Sub
Any help would be greatly appreciated. Thanks in advance.
It all depends on what you need to do.
If you want to display all records and navigate to the selected record, then you can use bookmark navigation:
With Forms!MyOtherForm
.RecordsetClone.FindFirst "struct_ID = " & Me!struct_ID
If Not .RecordsetClone.NoMatch Then
If .Dirty Then
.Dirty = False
End If
.Bookmark = .RecordsetClone.Bookmark
End If
End With
This assumes that the other form is open with all the records loaded.
Another approach to this problem, which I find more useful for popup situations like this, is to just open the other form as a dialog and require it be closed before returning to the calling context. In that case, you'd do this:
DoCmd.OpenForm "MyOtherForm", , , "struct_ID = " & Me!struct_ID, , acDialog
You'd then have to close the other form to get back to the original context.
You might think that with large numbers of records this would be inefficient, but it's actually very fast, as this operation is highly optimized within Access (moreso than filtering an already open form, in fact).