- 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-06-2019 02:32 AM
Hi, you are right. I updated one line of code, now it will work as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 02:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 02:03 AM
Hi Manas,
where are we calling the time_card table and the time card records with u_export = false?
- Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 02:05 AM
Hi Sai,
I already shared the complete code with you. Kindly check in the replies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 02:12 AM
var gr = new GlideRecord("time_card");
gr.addQuery("u_export",false);
gr.query();
while(gr.next()) {
gr.monday = updateValue(gr.getValue("monday"));
gr.tuesday = updateValue(gr.getValue("tuesday"));
gr.wednesday = updateValue(gr.getValue("wednesday"));
gr.thursday = updateValue(gr.getValue("thursday"));
gr.friday = updateValue(gr.getValue("friday"));
gr.saturday = updateValue(gr.getValue("saturday"));
gr.sunday = updateValue(gr.getValue("sunday"));
gr.update();
}
function updateValue(data)
{