how to manipulate entity field values in drupal 7 in custom module I am creating a Payroll entity in which I have to manipulate different field values based on another field value (see below).

I have the following fields and I want to calculate the bottom four field values from the value of the basic salary field. Is there any function/hook available for this or do I have to write my own custom function?


basic salary field
da salary(daily allowance) 
ta salary(travel allowance)
epf salary(Employee provident fund)
save_salary(Save salary)
My suggestion, now that I understand you're trying to calculate certain values' amounts based on the amount of a different field, would be to use the Rules module.

Then you can accomplish what you need without writing a custom module.  Rules are sometimes a little clunky to create, but the module is really reliable - I use rules for all sorts of things, and once you set it up, it works beautifully.

Here are (roughly) the steps you'd need to take to create a rule that modifies a certain field based on another one.  Adjust as you need to, so it suits your particular needs.


After enabling the module, go to /admin/config/workflow/rules to add a new rule
Set the 'Event' that triggers the rule to be something like 'After updating existing content'.  That will trigger this re-calculation any time the node is updated
Next you'll see that the rule also has 'Conditions' and 'Actions'.  Set the 'Condition' for your rule to be 'Content is of type' and select the content type you want to apply this rule to from the given list.


Finally, let's go onto the actions.  You'll have to do two steps for each of the fields you're modifying 1) First calculate the value from the base_salary field (and store in temporary variable -- that's how it works) and 2) set the appropriate field with the value of this temporary variable.  Here are the 'Action' options that correspond to these


When you're calculating the value for one of the fields, the interface has, by default, a field to select from the top, an operator, and then a text field into which you can enter a number.  If you would rather add/multiply/etc two fields, just change the bottom one to a data selection option with the following button


If your calculation is more complicated than simply adding/subracting/etc two values, just keep selecting the 'Calculate' value action and keep working on the number with multiple chain operations until you're ready and then add the 'Set a data value' at the end.


Hope this helps! I can't do an entire tutorial on using Rules here, as it's a complicated module, but the above should get you started and point you in the right direction. :0)