On Google Sheets;
I want it to display Day/Month/Year & Hour/Minute
When I click Insert date it shows 6/20/2015 21:59:4
I want it to show 20/06/2015 21:59
I have tried a few things and I managed to change the month/day around but it threw up errors so had to start again.
If anyone has better code or can fix this code It would help alot!
function getDate() {
var d = new Date();
return (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
}
function getTime() {
var d = new Date(),
offset = -d.getTimezoneOffset()/60,
h = d.getUTCHours() + offset,
m = d.getMinutes(),
s = d.getSeconds();
return h + ":" + m + ":" + s;
}
function getDateAndTime() {
return getDate() + " " + getTime();
}
function insertValue(theValue, format) {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
theSheet = ss.getActiveSheet(),
theCell = theSheet.getActiveSelection();
theCell.setNumberFormat(format || theCell.getNumberFormat());
theCell.setValue(theValue);
return true;
}
function getValue() {
return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell().getValue();
}
function getFormat() {
return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell().getNumberFormat();
}
function insertDate() {
insertValue(getDate(), "Date");
}
function insertTime() {
insertValue(getTime(), "Time");
}
function insertDateAndTime() {
insertValue(getDateAndTime(), "Date time");
}
function appendDate() {
insertValue(getValue() + " " + getDate());
}
function appendTime() {
insertValue(getValue() + " " + getTime());
}
function appendDateAndTime() {
insertValue(getValue() + " " + getDateAndTime());
}
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Insert Date", functionName: "insertDate"});
menuEntries.push({name: "Insert Time", functionName: "insertTime"});
menuEntries.push({name: "Insert Date and Time", functionName: "insertDateAndTime"});
menuEntries.push(null); // line separator
menuEntries.push({name: "Append Date", functionName: "appendDate"});
menuEntries.push({name: "Append Time", functionName: "appendTime"});
menuEntries.push({name: "Append Date and Time", functionName: "appendDateAndTime"});
ss.addMenu("Insert Date", menuEntries);
}
function onInstall() { onOpen(); }
does this formula work as you want:
=TEXT(NOW(),"dd/mm/yyyy hh:mm")
Maybe use Utilities.formatDate().
See here for more info
example:
var formattedDate = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm");
Related
I have retrieved the date from Rest API. The outcome becomes invalid date. Below is my code. Could you please help me if there is wrong format?
ngOnInit() {
this.reportList$ = [];
from(this.mcsService.getReportList().then(res => {
for (let item of res.data.items as ReportSummaryItem[]) {
let itemDate = new Date(item.createdOn);
item.createdOn = itemDate.toLocaleDateString('en-GB') + ' ' + itemDate.toLocaleTimeString();
console.log("Report Created Date"+item.createdOn);
this.reportList$.push(item);
}
this.ref.detectChanges();
return res.data.items;
}));
}
Here is function from Rest API where the date is retrieved.
function getRows(req, res) {
var parameter = { 'createdBy': req.user.username };
var limitParam = '';
var offsetParam = '';
if (typeof req.query.offset === 'undefined') {
offsetParam = ' OFFSET 0 ';
} else {
offsetParam = ' OFFSET ' + req.query.offset;
}
if (typeof req.query.limit === 'undefined') {
limitParam = ' ROWS FETCH NEXT 100 ROWS ONLY ';
} else {
limitParam = ' ROWS FETCH NEXT ' + req.query.limit + ' ROWS ONLY ';
}
req.oracleMobile.database.sql(
'SELECT tr."id", tr."observation", '
+ 'TO_CHAR(tr."createdOn" AT TIME ZONE \'+00:00\', \'dd-MON-yy\') as "createdOn" '
+ 'FROM "' + req.tarTable + '" tr ' +
' WHERE tr."createdBy" = :createdBy ' +
' ORDER BY tr."createdOn" desc ' + offsetParam + limitParam, parameter
).then(
function (result) {
res.status(result.statusCode).send(result.result);
}, function (err) {
res.status(err.statusCode).send(errorHandler.restErrorHandler(err));
}
);
}
I think the format of the date returned is not compatible. It's better to format it following ISO 8601 (yyyy-mm-ddThh:mm:ss.ffffff).
Change your SQL to:
+ 'TO_CHAR(tr."createdOn" AT TIME ZONE \'+00:00:00\', \'yyyy-MON-dd\') as "createdOn" '
... or something like that (not sure about the syntax as I'm not using oracleMobile database.
I have a table with 2 columns: Keys and Values.
The keys are dates, formatted with the sap time format.
Something like this:
"/Date(1510700400000)/"
I have a function which shows the date in a readable form.
convertDate: function() {
if (value === 'null') {
return value.replace('null', 'no date specified')
} else {
var d = new Date(parseInt(value.replace('/Date(', '').replace(')/', ''), 10))
}
var month = d.getUTCMonth() + 1 // months from 1-12
var day = d.getUTCDate()
var year = d.getUTCFullYear()
return year + '/' + month + '/' + day
},
I access my value via:
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({
text: "RDATE"
}),
sortProperty: "RDATE",
template: new sap.ui.commons.TextView().bindProperty("text", "key")
}));
Now I want to call my function on "key".
How can I accomplish that? :)
You can achieve this using a formatter function.
template: new sap.ui.commons.TextView().bindProperty("text", {
path: "key",
formatter: function(value){
if (value === 'null') {
return value.replace('null', 'no date specified')
} else {
var d = new Date(parseInt(value.replace('/Date(', '').replace(')/', ''), 10))
}
var month = d.getUTCMonth() + 1 // months from 1-12
var day = d.getUTCDate()
var year = d.getUTCFullYear()
return year + '/' + month + '/' + day
}
});
Reference: https://sapui5.netweaver.ondemand.com/#/topic/07e4b920f5734fd78fdaa236f26236d8
I've been using the below script which is working fine, however I'd like to cut down on the number of times it triggers.
function sendNotification(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//var sheet = ss.getSheetByName("Allocation Requests");
var sheet = ss.getActiveSheet();
var row = sheet.getActiveRange().getRow();
var cellvalue = ss.getActiveCell().getValue().toString();
var emailAdd = "email#yourdomain.com";
if(event.range.getA1Notation().indexOf("G") > -1 && sheet.getRange("G" + row).getDisplayValue() && emailAdd.length > 1)
{
{var confirm = Browser.msgBox('Case Quantity', 'Is this a confirmed amount?', Browser.Buttons.YES_NO);
if(confirm!='yes'){return};
var rowVals = getActiveRowValues(sheet);
MailApp.sendEmail({
to: emailAdd,
subject: "Allocation Request - " + rowVals.quantity + " cases on " + rowVals.date,
htmlBody: "There has been a new allocation request from " + rowVals.name + " in the " + rowVals.team + " team.<br \> <br \> "
+ "<table border = \"1\" cellpadding=\"10\" cellspacing=\"0\"><tr><th>Issuing Depot</th><th>Delivery Date</th><th>Case Quantity</th></tr><tr><td>"+rowVals.depot+"</td><td>"+rowVals.date+"</td><td>"+rowVals.quantity+"</td></tr></table>"
});
}
}
/**
* get values of depot, date, quantity and name from their respective cells.
* #returns {Object.<string, string>}
*/
function getActiveRowValues(sheet){
var cellRow = sheet.getActiveRange().getRow();
// get depot value
var depotCell = sheet.getRange("E" + cellRow);
var depot = depotCell.getDisplayValue();
// get date value
var dateCell = sheet.getRange("F" + cellRow);
var date = dateCell.getDisplayValue();
// get quantity value
var quantCell = sheet.getRange("G" + cellRow);
var quant = quantCell.getDisplayValue();
// return an object with your values
var nameCell = sheet.getRange("B" + cellRow);
var name = nameCell.getDisplayValue();
var teamCell = sheet.getRange("C" + cellRow);
var team = teamCell.getDisplayValue();
return {
depot: depot,
date: date,
quantity: quant,
name: name,
team: team
} }
}
Users enter more than one row of data at a time, and I would like to receive a notification when that user has finished entering data, but still send the information in the email for all the rows they've entered. At present I get an email each time they complete a row.
Am calling readPlaceName from TourGuideController, and passing the string in method readPlaceName(Placename), the cursor is showing null pointer exeception, not showing any values,Can any give solution for this error?
TourGuideController.java
public Cursor readPlaceName(String place_name){
String sql = "SELECT * FROM " + TourGuideDatabasehandler.VISTING_INBETWEEN_PLACES +
" WHERE "+ TourGuideDatabasehandler.PLACE_NAME + " = '" + place_name+"'";
Log.e("","Sql "+sql);
Cursor v = database.rawQuery(sql,null);
Log.e("v","Cursor v : "+v.toString());
return v;
}
MainActivity.java
protected void onPostExecute(Void result) {
super.onPostExecute(result);
int time = t_time;
TourGuideController dbcon = new TourGuideController(ourcontext);
System.out.println("dbcon"+dbcon+"temp_dbcon"+dbcon);
Log.e("OPEN","DB OPEN "+dbcon);
String place = "Juhu Beach";
Cursor cursors = dbcon.readPlaceName(place);
Log.e("dpopen", "cursor"+cursors);
Log.e("Updating cursor and cursor", DatabaseUtils.dumpCursorToString(cursors));
Integer wait_time = null;
while(cursors.moveToNext())
{
wait_time = Integer.parseInt(cursors.getString(8));
}
cursors.close();
String google_distance_time = "5";
Integer google_time = null;
google_time = Integer.parseInt(google_distance_time);
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
LocalTime time1 = formatter.parseLocalTime(start_time);
System.out.println("wait_time"+wait_time);
int pred_time = (wait_time) + (google_time);
int get_total_time = (time)-(pred_time);
total_time = String.valueOf(get_total_time);
int addTimeMin = pred_time;
time1 = time1.plusMinutes(addTimeMin);
prediction_time = String.valueOf(time1);
dbcon.updateDateTime(place, start_date, start_time,google_distance_time,prediction_time,total_time);
Cursor cursor2 = dbcon.readPlaceName(place);
Log.e("Updating time and date", DatabaseUtils.dumpCursorToString(cursor2));
}
}}
Is it possible to add a user to a group via REST/sdk?
Scenario: We want to add all our users to a mandatory group on a regularly basis.
Thanks!Max
you can get group ids from share point list like this
function GetMandatoryGroups() {
var context;
var factory;
var appContextSite;
var oList;
var collListItem;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostweburl);
this.web = appContextSite.get_web();
oList = this.web.get_lists().getByTitle('MandatoryGroups');
context.load(oList);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
collListItem = oList.getItems(camlQuery);
context.load(collListItem, 'Include(Title,Id)');
context.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);
function successHandler() {
MandatoryGroups = new Array();
var listItemInfo = '';
var listitemenumerator = collListItem.getEnumerator();
while (listitemenumerator.moveNext()) {
var olistitem = listitemenumerator.get_current();
//listItemInfo += '<li>ID:' + olistitem.get_id().toString() + ' GroupID: ' + olistitem.get_item('Title') + '</li>';
MandatoryGroups.push(olistitem.get_item('Title'));
}
AutoJoinGroups();
// document.getElementById("message").innerHTML = 'Lists found' + oList.get_title() + ':<ul>' + listItemInfo + '</ul>';
}
function errorHandler(sender, args) {
document.getElementById("message").innerText =
"Could not complete cross-domain call: " + args.get_message();
}
}
you can join users to the mendatory groups like this (after user logs in )
function AutoJoinGroups() {
yam.platform.request({
// yam.request({
url: "groups.json?mine=1",
method: "GET",
data: {},
success: function (group) {
//for ($i = 0; $i < MandatoryGroups.length; $i++) {
// if (!ArrayContains(MandatoryGroups[$i].toString(), group)) {
// joinGroupAsync(MandatoryGroups[$i].toString());
// setTimeout('', 10000);
// // setTimeout(joinGroupAsync(MandatoryGroups[$i].toString()),5000);
// }
//}
var i = 0;
function AsyncAutoJoinLoop() {
if (i < MandatoryGroups.length) {
if (!ArrayContains(MandatoryGroups[i].toString(), group)) {
setTimeout(function () {
joinGroupAsync(MandatoryGroups[i].toString());
i++;
if (i < MandatoryGroups.length) {
AsyncAutoJoinLoop();
}
}, 3000)
}
}
}
AsyncAutoJoinLoop();
// getMyGroups();
},
error: function (group) {
console.error("There was an error with the request.");
}
});
}
function joinGroupAsync(id) {
yam.platform.request({
// yam.request({
url: "group_memberships.json?group_id=" + id,
method: "POST",
data: {},
success: function (group) {
},
error: function (group) {
console.error("There was an error with the request.");
}
});
}
you can add group to the sharepoint list like this.
function InsertMandatoryItem() {
var context;
var factory;
var appContextSite;
var oListItem;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostweburl);
this.web = appContextSite.get_web();
var oList = this.web.get_lists().getByTitle('MandatoryGroups');
var itemCreateInfo = new SP.ListItemCreationInformation();
oListItem = oList.addItem(itemCreateInfo);
oListItem.set_item('Title', InsertGroupId);
oListItem.update();
context.load(oListItem);
context.executeQueryAsync(
Function.createDelegate(this, onQuerySucceeded),
Function.createDelegate(this, onQueryFailed)
);
function onQuerySucceeded() {
//alert('Item created: ' + oListItem.get_id());
// getMyGroups();
// AutoJoinGroups();
$.getScript(scriptbase + 'SP.RequestExecutor.js', GetMandatoryGroups);
}
function onQueryFailed(sender, args) {
$.getScript(scriptbase + 'SP.RequestExecutor.js', GetMandatoryGroups);
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
}
You can remove remove group from sharepoint list like this
function RemoveMandatoryGroup() {
var context;
var factory;
var appContextSite;
var collListItem;
var itemId;
context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostweburl);
this.web = appContextSite.get_web();
var oList = this.web.get_lists().getByTitle('MandatoryGroups');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + RemoveGroupId.toString() + "</Value></Eq></Where></Query></View>");
collListItem = oList.getItems(camlQuery);
context.load(collListItem, 'Include(Title,Id)');
// this.oListItem.deleteObject();
context.executeQueryAsync(
Function.createDelegate(this, onQuerySucceeded),
Function.createDelegate(this, onQueryFailed)
);
function onQuerySucceeded() {
var oListItem;
var listitemenumerator = collListItem.getEnumerator();
while (listitemenumerator.moveNext()) {
var itemtoDelete = listitemenumerator.get_current();
////listItemInfo += '<li>ID:' + olistitem.get_id().toString() + ' GroupID: ' + olistitem.get_item('Title') + '</li>';
//MandatoryGroups.push(olistitem.get_item('Title'));
itemId = itemtoDelete.get_id();
}
oListItem = oList.getItemById(itemId);
oListItem.deleteObject();
context.executeQueryAsync(Function.createDelegate(this, onQueryDeleteSucceeded), Function.createDelegate(this, onQueryDeleteFailed));
//alert('Item created: ' + oListItem.get_id());
function onQueryDeleteSucceeded() {
//alert('Request failed. ' + args.get_message() +
// '\n' + args.get_stackTrace());
getMyGroups();
$.getScript(scriptbase + 'SP.RequestExecutor.js', GetMandatoryGroups);
}
function onQueryDeleteFailed() {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
}
No, there isn't. This is by design. Yammer likes to entice with the carrot, not by the stick. What we've done is create communications to ask people to join a specific group.
The api does allow the ability for the currently logged to be joined to a specific group. E.g. Put a link on a SharePoint site that says "Join the Yammer group", and have the action join that user to the group. You can see the details for how to do that here:
https://developer.yammer.com/restapi/#rest-groups
ya, in costume app yo can autojoin that user when he logs in..Same thing i ma doing.