Go Back   SugarCRM Forums > Community Forums > Help
 Create an account

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 2006-11-07, 06:44 AM
sagarladdha sagarladdha is offline
Senior Member
 
Join Date: Oct 2006
Posts: 70
Default Adding a field which is generated after some calculation?

Hi,

I have to add a field in Detail View of Cases module. I have written a function which calculates the age of a case by subtracting the date_entered value from current date. Now, I have to display this field in Detail View.

Initially, I edited the DetailView.html file and added the code for displaying the field. But after doing this, I changed the location of some other field in the Detail View using studio. Alas! the DetailView.html had been overwritten. So, I had to write the 2 lines of code for displaying the Case Age field again. The calclation part was done in Case.php so only the display part had to be re-written.

But I want the Case Age field to be displayed there, even if changes have been made using studio.

Can anyone help in this regard?

Thanks in advance,

Sagar Laddha
India
Reply With Quote
  #2  
Old 2006-11-08, 07:44 AM
aschaeffer aschaeffer is offline
Senior Member
 
Join Date: Oct 2006
Location: Vienna, Austria
Posts: 35
Default Re: Adding a field which is generated after some calculation?

Hi!

You're using sugar 4.5? If yes it's quite simple. You have to do the changes in
\custom\working\modules\MODULE

Then you go in the studio, get to the module and view you just changed and hit Save and apply changes.

Now I have a question for you: How did you calculate the age? can you give the php lines?
Is the result of this calculation beeing saved in the DataBase? Because I did some calc but put then in EditView.php and they just display but are not saved in DB.

Thanks!
Alan
Austria
Reply With Quote
  #3  
Old 2006-11-08, 10:29 AM
sagarladdha sagarladdha is offline
Senior Member
 
Join Date: Oct 2006
Posts: 70
Default Re: Adding a field which is generated after some calculation?

Quote:
Originally Posted by aschaeffer
Hi!

You're using sugar 4.5? If yes it's quite simple. You have to do the changes in
\custom\working\modules\MODULE

Then you go in the studio, get to the module and view you just changed and hit Save and apply changes.

Now I have a question for you: How did you calculate the age? can you give the php lines?
Is the result of this calculation beeing saved in the DataBase? Because I did some calc but put then in EditView.php and they just display but are not saved in DB.

Thanks!
Alan
Austria

Thanks a tonne for your help. i could never have figured this thing out. My problem is solved now.

You wanted the code for Case Age. right?. First of all, I did not understand why do you want to save the age in database. Becase the age will be a dynamic field which will change with time (atleast in my case). What I am doing is a pretty simple thing. Just subtracting the date_entered value from current date. if I save this value in database, then next time when I view the Detail View of that case, it will show me the incorrect age, isnt it? So, I did not use it in the Edit View nor did I store it in database.

If you still want the code, I will give it to you. But just check once the reason for which you want the age to be stored in database.

Thanks once again.
Reply With Quote
  #4  
Old 2006-11-08, 11:30 AM
aschaeffer aschaeffer is offline
Senior Member
 
Join Date: Oct 2006
Location: Vienna, Austria
Posts: 35
Default Re: Adding a field which is generated after some calculation?

Actually I don't want to use your function for the same purpose. I made a field supposed to be the sum of 2 others and saved in DB. On the other hand I want to calculate the duration in month of a contract: Date End - Date Start = duration in months.
So your calc would help me a lot to figure out how to do mine! So thanks for sending it!

Cheers,
Alan
Reply With Quote
  #5  
Old 2006-11-08, 01:19 PM
sagarladdha sagarladdha is offline
Senior Member
 
Join Date: Oct 2006
Posts: 70
Default Re: Adding a field which is generated after some calculation?

I have not sent you the code yet. Do you want it here or should I send it on your personal id? Let me know your id, if you want it through mail.

Regards
Reply With Quote
  #6  
Old 2006-11-08, 01:23 PM
aschaeffer aschaeffer is offline
Senior Member
 
Join Date: Oct 2006
Location: Vienna, Austria
Posts: 35
Default Re: Adding a field which is generated after some calculation?

Please post it here on this thread so everyone can use it! Thanks!
Alan
Reply With Quote
  #7  
Old 2006-11-08, 01:55 PM
chrisky chrisky is offline
A Prolific Poster
 
Join Date: Aug 2006
Location: Trondheim, Norway
Posts: 293
Default Re: Adding a field which is generated after some calculation?

Al,

I did hear your request the other day to store the calculated value(s) to the db..

This is easy as pie...

Simplest way for ya is to just create a new *cringe* custom field in that module, then inside the corresponding view php file, something like the following:
$CUSTOMFIELD_NAME = $MY_CALCULATED_SUM

though the user would still have to 'save' the record, but if you handle all of this in the editview, you're good to go..
Reply With Quote
  #8  
Old 2006-11-08, 03:12 PM
aschaeffer aschaeffer is offline
Senior Member
 
Join Date: Oct 2006
Location: Vienna, Austria
Posts: 35
Default Re: Adding a field which is generated after some calculation?

Hey Chris,

Looked quite easy indeed... but it doesn't work

In EditView.php
$sumfngebuehr = (($focus->jan2006_c) + ($focus->ist_totalturnover_c));
$SCAN_TOTAL_C = $sumfngebuehr ;

I also tried
$scan_total_c = $sumfngebuehr ;

Nothing happens. Any idea?
Wouldn't it be possible to make something like a "calculate" button that make the calculations, display them in the respective fields and then the user can save?
Reply With Quote
  #9  
Old 2006-11-08, 04:01 PM
chrisky chrisky is offline
A Prolific Poster
 
Join Date: Aug 2006
Location: Trondheim, Norway
Posts: 293
Default Re: Adding a field which is generated after some calculation?

You're overcomplicating it..

No need for a button, this or that.. lol

Lets take a step back and make sure we're on the same page.

At this point, you do have your calculated sum [of two fields] being displayed to the user on some page/screen?

EditView, or DetailView in a particular module, right?

If that is correct so far, then what you want to do is create a custom field in that same module, and for entertainment purposes, also place that custom field in your view file layout.. In simplicity, you want that the end user to see that custom field and be able to use it (enter data in it if they're in the EditView) and see it on the DEtailView page.. This step isn't technically neccessary but it greatly helps the devloper 'see' things working, and identify where at what stage a problem exists, if things aren't working right...

Once you have this new custom field created, and function without problem which means you test it a few times, in EditView you enter data in this field for a record or two, and then verify that it is saved to the db, and that it is displayed in the DetailView, and also that it is displayed and retrieved within EditView when you come back to the EditView 5 mins later..

There are alot of ways to pass/populate the data to that field, from many different places as well which include svr side php code or even on the client side via js; however, the simplest solution and how I would do it is just passing the data between the two variables which is this single line of code: $SCAN_TOTAL_C = $sumfngebuehr ;

Pretty easy eh? Just one line of code is all ya need in order to accomplish this little goal..
Reply With Quote
  #10  
Old 2006-11-09, 12:31 PM
aschaeffer aschaeffer is offline
Senior Member
 
Join Date: Oct 2006
Location: Vienna, Austria
Posts: 35
Default Re: Adding a field which is generated after some calculation?

I think I got what you're describing.

But the thing is, the user has to:
1 - enter a number in field jan2006_c and feb2006_c
2- save (the sum is not beeing displayed in DetailView)
3- edit again and save
4- now the sum displays in EditView.

So I have to find a way to perform calculation before saving. I made a thread specifically for that purpose in the developper forum:
http://www.sugarcrm.com/forums/showthread.php?t=18019

Also, I don't use $SCAN_TOTAL_C = $sumfngebuehr it just doesn't seem to do anything...

See you later,
Alan
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:14 AM.


Powered by: vBulletin
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SourceForge.net Logo