I have 2 items :P1_START_DATE and :P1_END_DATE.
I need to display the current date in these two field when I double click the items, I need this through dynamic action.
Thanks!
Abinnaya
You can create a Dynamic Action that triggers on Event: Double Click, Selection Type: Item(s), and Item(s): :P1_START_DATE for each of your items.
Then your True Action should be Execute JavaScript with the code like this:
var myDate = new Date();
var dd = String(myDate.getDate()).padStart(2, '0');
var mm = String(myDate.getMonth() + 1).padStart(2, '0');
var yyyy = myDate.getFullYear();
// Here you can format your date the way you want it to look.
myDate = mm + '/' + dd + '/' + yyyy;
apex.item("P1_START_DATE").setValue(myDate);
When you know how to create a dynamic action you can use:
Set Value
Setting -> PL/SQL Function Body
begin
return to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'); -- or your format mask
end;
Affected Items: P1_START_DATE, P1_END_DATE
I try to avoid JavaScript where possible.
Related
I have a list of 12 month names, let's say ['AAA', 'BBB', ...]. In reality, they are kind of historical, so not included in any typical locale.
Now I want them to be included into my DateFormat('yMMMMd') instead of the normal names. I am not able to build the date string manually like
var myDateStr = myMonthName + ' ' + myDay + ', ' + myYear; // US
var myDateStr = myDay + '. ' + myMonthName + ' ' + myYear; // DE
because I want to keep the format of the chosen locale nonetheless. The day/month/year order changes with the chosen locale, which I want to keep. I just want to replace the month name. A RegExp replace or similar is not easily possible, I guess, because of the different date formats and language specific month names.
Expected result:
For chosen US locale: AAA 1st, 2022
For chosen DE locale: 1. AAA 2022
of course, every other locale format must be supported...
Do you have any ideas?
Is it possible to just insert custom month names into DateFormat object?
I recently had an idea, which seems to work:
var dateStr = DateFormat('yMMMMd', myLocale).format(myDate);
var monthName = DateFormat('MMMM', myLocale).format(myDate);
return dateStr.replaceFirst(monthName, 'AAA');
// or
return dateStr.replaceFirst(monthName, myHistoricalNames[myDate.month - 1]);
First create the normal date string to receive the locale's date format.
Calculate another date string which only includes the locale's month name. Now I know the string which I need to replace in dateStr no matter which language I choose.
Replace the month name with my custom month name.
I currently have a start date in cell C1 and end date in C2 of a Google Sheet spreadsheet. I would like to set it up so that if no date is entered in the end date (C2), this cell will be auto-populated with today's date
I have thus far found the following script
function onFormSubmit(e) {
//edit responses sheet name
var responseSheetName = 'Stats';
//Edit colmn number, column in which the date has to be autopopulated
var column = 3;
//Get target row number
var row = e.range.rowStart;
//If no date, pouplate the cell with current date
if(!e.values[column-1]){
SpreadsheetApp.getActive().getSheetByName(responseSheetName).getRange(row, column).setValue(new Date())
}
}
This doesn't seem to be doing the trick so either I am reading it wrong, it is not what I am looking for!
Is this something that is possible?
I have question. We are making a planning tool for one of our internal products. In this tool we can switch the status of an item (in this case a package) manually (drop down menu)(column E). Based on the status it is ending up in one of the employees planning overview tabs. But, every packages has an offline date (column G). This date is the moment that the package will go offline automatically. Based on the offline date I would like to switch the cell status automatically to 'Offline'. The problem is that this cell could also be changed manually (for other status).
I was thinking, may be there is a trick with conditional formatting to also change the value / text inside a cell. When the present date is the 'offline date' or later than the offline date the conditinal formatting will change the status of the cell to: "Offline".
Does anyone have a trick for this? Thank you in advance!
Link to example sheet: Stackoverflow example date changes cell sheet
This function does change the status in column E to 'Offline' if its accompanying offline date in column G is equal to the date the function is running.
Script:
function changeStatusToOffline() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var lastRow = sheet.getLastRow();
// column E for status
var statusRange = sheet.getRange(2, 5, lastRow - 1, 1);
var statusValues = statusRange.getValues();
// column G for offline dates
var offlineDateRange = sheet.getRange(2, 7, lastRow - 1, 1);
var offlineDateValues = offlineDateRange.getValues();
// set time properties of today to 0 to compare date values only
// do the same with the individual offline dates later
var todayDate = new Date();
todayDate.setHours(0,0,0,0);
var todayTime = todayDate.getTime();
// generate status output during iteration of date values
var statusOutput = offlineDateValues.map((offlineDateValue, index) => {
// the same with today's date
var offlineDate = new Date(offlineDateValue);
offlineDate.setHours(0,0,0,0)
var offlineTime = offlineDate.getTime();
// if trigger date value is same as offline date value, change status to offline
if (todayTime == offlineTime)
return ['Offline'];
// use existing value if date are not the same
return statusValues[index];
});
// set the status range by bulk
statusRange.setValues(statusOutput);
}
Note:
Test the script by running it manually
If it successfully does what you need, then proceed on setting up a daily trigger and trigger the function above daily on a specific time. (e.g. Daily 12AM)
This only updates the status IF trigger date is equal to offline date. (This makes the trigger change the status change to offline just once)
Only if you change the offline date to a later date, then it will be possible to automatically update the status when the script runs on that date again.
Before:
After:
I wondered if anyone could help. I have a script where I am pulling out data from a spreadsheet list, where this is a match for this week (basically an events list, to produce a weekly agenda). I will use a for loop to increment the days to add on, but I am just trying to make it work for one day for now...
The first column is the data in format dd/mm/yyy
I am trying to take today's increment by 1 and then search through the list to find a match. The searching etc, I can make work, but the date part is just not playing. I wondered if anyone could advise.
E.g. Date Column A:
06/07/2021
06/07/2021
01/11/2021
01/11/2021
01/11/2021
01/11/2021
02/09/2021
02/09/2021
var selectedDate = row[0];
selectedDate = Utilities.formatDate(new Date(selectedDate), "GMT+1", "dd/MM/yyyy");
var currdate = new Date();
currdate = Utilities.formatDate(new Date(selectedDate), "GMT+1", "dd/MM/yyyy");
var daystochange = 1;
var newdate = new Date(currdate.getFullYear, currdate.getMonth, currdate.getDay+daystochange );
Could anyone help?
Thanks
Only use Utilities.formatDate() to output dates, not to work with dates.
The JavaScript date object has all you need to work with dates and compare. When you use the Utilities function it converts it to a string, and so you lose all the functionality of the Date object.
Also bear in mind that if you have dates, that are formatted as dates in your sheet, they will automatically be returned as Date objects.
For example, if your sheet has a date in cell A1
var date = Sheet.getRange("A1").getValue()
date instanceof Date // true
Once you have your date, if you want to add one day to it, you can take an approach similar to what you have already done:
var selectedDate = new Date(2021, 1, 15)
var newdate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate() + 1);
console.log(newdate) // Tue Feb 02 2021 00:00:00
Note - use getDate to return the day of the month, getDay only returns day of the week.
To check if two dates are the same, you can write a function to compare:
function isSameDate(a, b) {
return a instanceof Date &&
b instanceof Date &&
a.getYear() === b.getYear() &&
a.getMonth() === b.getMonth() &&
a.getDate() === b.getDate()
}
This function will return true if the dates are the same.
Reference
Date
I have a LibreOffice Base form that allows me to manually add rows to a table. However, the first field of every row is almost always a duplicate of the previous rows first field - Date. Via a macro, I want to automatically fill in the date field so I don't have to manually repeat the information.
Using the PriorToReset event handler, I tried the following:
Sub Main
Dim defaultDate as string
End Sub
Sub PriorToReset(event)
dim Form
dim DateField
Form=event.source
DateField = Form.getByName("Date")
if DateField.Text = "" then
defaultDate = Date
DateField.Text = defaultDate
else
defaultDate = DateField.Text
end if
End Sub
This does put the current date into an empty row, but when I fill out the remaining fields and attempt to save the row, it objects by saying that the Date field is empty. I'm looking at todays date in that field, but the system acts like its empty. If I backspace over just the last digit, replace it and hit enter it accepts it.
Obviously just dumping the date into the "Text" property does not set the indicator that data has been entered. I also experimented with:
DateField.setPropertyValue("Text", defaultDate)
But that errors out completely.
How do I simulate data entry via a macro?
Set the date property of DateField using a variable declared as an UNO Date Struct.
First, declare the struct. Then set the values of the individual members of the struct (year, month, day). Then set the date property to equal the struct and commit.
Adapt this code example to suit:
Sub change_a_date
Dim adate As New com.sun.star.util.Date
root_form = ThisComponent.Drawpage.Forms
main_frm = root_form.getByName("MainForm")
adate.year = 1990
adate.month = 7
adate.day = 4
main_frm.getByName("date_bx").date = adate
main_frm.getByName("date_bx").commit
End Sub
Declaration based on example for IsStruct function. See also API reference for UNO Date Struct.