- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 09:49 PM
Hi All,
I need your help with the code of a fix script on below requirement.
For all the unexported time cards (u_export= false) on the time card table, if the minutes are not: 0,0.25,0.5,0.75 it should change it to the closest of those values.
Conditions are....
u_export= false &
1. If the provided time is equal or above 0.15 then it should set the value to 0.25 and if it is less that 0.15 then it should set the value to 0
2. If the provided time is equal or above 0.37 then it should set the value to 0.50 and if it is less that 0.37 then it should set the value to 0.25
3. If the provided time is equal or above 0.62 then it should set the value to 0.75 and if it is less that 0.62 then it should set the value to 0.50
4. If the provided time is equal or above 0.87 then it should set the value to 1.0 and if it is less that 0.87 then it should set the value to 0.75
Example:
Monday (u_monday)
8 -> No modification
Tuesday (u_tuesday)
5.25 -> No modification
Wednesday (u_wednesday)
7.11 ->becomes 7
Thursday (u_thursday)
7.18 ->becomes 7.25
Friday (u_friday)
2.70 ->becomes 2.75
Saturday (u_saturday)
2.60 ->becomes 2.50
Sunday (u_sunday)
9.74 ->becomes 9.75
Note - All are decimal fields.
- Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 01:29 AM
Hi,
I am assuming that your u_export is a manually added field you want to filter by. So what you can do is to create a GlideRecord that queries all "u_export=false" records and then update all fields according to your requirements.
This script should work for you:
var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
var values = [];
var grTimeCard = new GlideRecord('time_card');
grTimeCard.addQuery('u_export', false);
grTimeCard.query();
while(grTimeCard.next()){ // for every time card
days.forEach(function(day, index){
values[index] = grTimeCard.getValue(day); // get the value for every day
});
days.forEach(function(day, index){ // recalculate the value
var numberSplitted = parseFloat(values[index]).toFixed(2).split('.');
var predecimal = numberSplitted[0];
var decimals = numberSplitted[1];
values[index] = decimals < 15 ? predecimal
: decimals < 37 ? predecimal + '.' + 25
: decimals < 62 ? predecimal + '.' + 50
: decimals < 87 ? predecimal + '.' + 75
: parseFloat(predecimal) + 1;
});
days.forEach(function(day, index){
grTimeCard.setValue(days[index], values[index]); // save the new value
grTimeCard.update();
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 11:15 PM
Kind regards,
Manas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2019 11:26 PM
Hi Manas,
Can you help me with the exact code as the code should run on time_card table with below conditions.
u_export= false
&
1. If the provided time is equal or above 0.15 then it should set the value to 0.25 and if it is less that 0.15 then it should set the value to 0
2. If the provided time is equal or above 0.37 then it should set the value to 0.50 and if it is less that 0.37 then it should set the value to 0.25
3. If the provided time is equal or above 0.62 then it should set the value to 0.75 and if it is less that 0.62 then it should set the value to 0.50
4. If the provided time is equal or above 0.87 then it should set the value to 1.0 and if it is less that 0.87 then it should set the value to 0.75
- Thank You.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 01:24 AM
@Ankur Bawiskar can you help me on this? Urgent...!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 01:29 AM
Hi,
I am assuming that your u_export is a manually added field you want to filter by. So what you can do is to create a GlideRecord that queries all "u_export=false" records and then update all fields according to your requirements.
This script should work for you:
var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
var values = [];
var grTimeCard = new GlideRecord('time_card');
grTimeCard.addQuery('u_export', false);
grTimeCard.query();
while(grTimeCard.next()){ // for every time card
days.forEach(function(day, index){
values[index] = grTimeCard.getValue(day); // get the value for every day
});
days.forEach(function(day, index){ // recalculate the value
var numberSplitted = parseFloat(values[index]).toFixed(2).split('.');
var predecimal = numberSplitted[0];
var decimals = numberSplitted[1];
values[index] = decimals < 15 ? predecimal
: decimals < 37 ? predecimal + '.' + 25
: decimals < 62 ? predecimal + '.' + 50
: decimals < 87 ? predecimal + '.' + 75
: parseFloat(predecimal) + 1;
});
days.forEach(function(day, index){
grTimeCard.setValue(days[index], values[index]); // save the new value
grTimeCard.update();
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 01:48 AM
Hi Paul,
When I give the time as 0.89 then it is setting the value to 0. It should actually set to 1.
If the provided time is equal or above 0.87 then it should set the value to 1.0 and if it is less that 0.87 then it should set the value to 0.75
- Thank you.