You could not convert the quantity field into a time field, but you could create a custom field that will accept hours and minutes (ie. 11:05 for 11 hours and 5 minutes). A client script could then reference the custom field's value and update the quantity column.
1) Create a Custom Transaction Body Field with the following settings:
Type : Free-Form Text
Applies To : Sale Item
2) Create a Client-side script triggered on 'Field Changed' events. The script will convert the hours and minutes entered in the custom column field into the number of hours recognized by the system (ie. 1.5 for 1 hours and 30 minutes)
- Navigate to Setup > Customization > Scripts > New
- Type : Client
- Use the Script below as the script file:
function fieldChanged(type, name) {
if(type == 'item') {
if(name == 'custcol6') { // custcol6 is id of custom transaction column field corresponding to time
serviceTime = nlapiGetCurrentLineItemValue('item', 'custcol6');
// split time into hours/minutes, using the ":" character as a separator
serviceTime = serviceTime.split(":");
serviceTime_hours = parseInt(serviceTime[0]);
serviceTime_minutes = parseInt(serviceTime[1]);
// get equivalent quantity for time entered
decimals = 2 // number of decimal places for quantity column. default is 2
serviceTime_quantity = serviceTime_hours + (serviceTime_minutes/60)
serviceTime_quantity = serviceTime_quantity.toFixed(parseInt(decimals));
nlapiSetCurrentLineItemValue('item', 'quantity', serviceTime_quantity, true);
}
}
}
- Use 'fieldChanged' as the function triggered on Field Changed Events
- Save the Script
3) After saving, create a Script Deployment by clicking the 'Deploy Script' button. Use the following settings for your Deployment
- Applies To : Invoice
- Status : Released
- Audience : All Roles
- Save the Deployment
4) Create/Edit an Invoice and notice the new column you created in step 1. Enter time in there and confirm that the quantity field is changed as well. For example, entering 2:30 in the custom column will update the quantity column to 2.5. Note that the format must be HH:MM, and the script might encounter errors if the format is not followed. The number of hours could exceed 2 digits.
*If you are unfamiliar with scripting, see Solution 19194 for an Overview of creating scripts
** This is alternate solution to Enhancement 249130 - Transactions > Sales > Create Invoices > Under Items tab enter a service item type > Under Quantity column please have the ability to enter hours and minutes instead of decimals
No comments:
Post a Comment