MomentsJS asHours formatting - momentjs

I have a result in milliseconds and I am trying to display it as Hours and Minutes using Momentjs.
var x = 161545000;
var tempResult = moment.duration(x);
var formattedX = tempResult.asHours() + 'h ' + tempResults.minutes() + 'm ';
What is being displayed:
2.2701202777777776h 16m
What I want, but can't seem to format it right:
2h 16m

How about using Math.floor()?
var formattedX = Math.floor(tempResult.asHours()) + 'h ' +
Math.floor(tempResults.minutes()) + 'm ';
Or, better yet, use the Moment#hours() method instead of Moment#asHours():
var formattedX = tempResult.hours() + 'h ' + tempResults.minutes() + 'm ';

Related

AX 2012 View computed column returning Null

I have a View in AX with a computed column:
private static server str qty()
{
#define.THEN(" THEN ")
#define.SINGLE_QUOTE("'")
return 'CASE T2.ReturnStatus ' +
' WHEN ' + int2str(enum2int(ReturnStatusLine::None)) + #THEN + '-1 * T3.UnitValue' +
' WHEN ' + int2str(enum2int(ReturnStatusLine::Awaiting)) + #THEN + '-1 * T3.UnitValue' +
' WHEN ' + int2str(enum2int(ReturnStatusLine::Registered)) + #THEN + '-1 * T3.UnitValue' +
' ELSE ' + "(T3.UnitValue / T2.ExpectedRetQty * (SELECT TOP 1 SUM(cpst.Qty) as RcvQty from custPackingSlipTrans as cpst where cpst.InventTransId = T2.InventTransId and cpst.dataAreaId='" + curext() + "')) * -1" +
' END';
}
It works great, except the past week or so the column is returning NULL when it should not be. This is fixed simply by going into the AOT and syncing this view, after that the column has a valid value. But we're having to do this almost daily.
Any ideas?

Displaying Date and Time information in script with format from spreadsheet

I'm working on a basic email-sending script in Google Sheets. I want to send email reminders on clicking a button, reminding people of an appointment at a date and time along with the location.
Everything works, except for the date is displayed in a confusing long form format:
The data shown in the date and time cells is:
8/27/2018
10:30 AM
The data being sent in the email is:
Mon Aug 27 2018 15:00:00 GMT+0800 (HKT)
Sun Dec 31 1899 02:30:00 GMT+0800 (HKT)
I only need to show the date and time as written in the sheets. Is there a way to do this?
Another question is that one person might have more than one appointment, can I combine all appointments date/time for each unique email address into one email instead of multiple emails?
Adding code below:
function sendArticleCountEmails() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("SSname"));
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange("B2:O2");
var data = dataRange.getValues();
for (i in data) {
var rowData = data[i];
var emailAddress = rowData[0]; //email
var recipient = rowData[1]; //name1
var message2 = rowData[2]; //Name2
var message3 = rowData[3]; //type
var message4 = rowData[4]; //Appt Date
var message5 = rowData[5]; //Appt Time
var message6 = rowData[6]; //Appt type
var message7 = rowData[7]; //Notes
var message8 = rowData[8]; //Facility Name
var message9 = rowData[9]; //Facility Address
var message10 = rowData[10]; //City
var message11 = rowData[11]; //Zip
var message12 = rowData[12]; //Phone
var message13 = rowData[13]; //Service
var message = 'Dear ' + recipient + ',\n\n' + 'This is a friendly reminder of your assignment tomorrow with:' + '\n\n' + message2 + ' at ' + message5 + '.'
+ '\n\n' + 'The assignment is located at ' + message8 + ', ' + message9 + ', ' + message10 + ', ' + message11 + '.' + '\n\n'
+ 'This assignment is noted as a ' + message6 + ' ' + message3 + ' ' + message13 + '. ' + message7 + '\n\n';
var subject = 'Reminder: ' + message4 + ' ' + message5 + ' (' + message2 + ')';
MailApp.sendEmail(emailAddress, subject, message);
}
}
I think the problem is here, using either var or rowData. The row is correct, just it doesn't pull the data in as shown in Sheets.
var message4 = rowData[4]; //Appt Date
var message5 = rowData[5]; //Appt Time
There is no time in the DATE cell (8/27/2018), so I'm guessing it defaults to "15:00:00" and because my data is input by mailparser, I don't have a method to change the format of the data. Rather I hope I can use the data as displayed in Google Sheets and display this into the Gmail.
I appreciate your suggestions in advance, thanks!

Firebase function transaction handle null value

I'm trying to use firebase function transaction, but as I see there is no official way to handle the first cached null value...
I'm trying to do the following:
var team = event.data.child('team').val();
var tip = event.data.child('tip').val();
console.log('tip: ' + tip + ' | team: ' +team)
const pathToValue = admin.database().ref('users/' + event.params.userId + '/coins');
const pathToTeamBetsValue = admin.database().ref('matches/' + event.params.matchId + '/opponents/' + team + "/bets");
return pathToValue.transaction(function (coins) {
if (coins) {
if (coins >= tip) {
pathToTeamBetsValue.transaction(function (teamBets) {
if (teamBets) {
teamBets = teamBets + tips;
return teamBets;
}
});
admin.database().ref('bets/' + event.params.matchId + '/' + event.params.userId + '/status').set('inProgress');
coins = coins - tip;
}
else {
console.warn(event.params.userId + " new bet on match " + event.params.matchId + " was not successfull! (not enough coin)")
//return coins;
}
}
return coins;
})
so far as you can see I get some value which what should be decreased from the user's coins... unfortunately till now I could only get the behaviour which sets null in the user's coin value.. please help

How to write script in BS in siebel to store multiple records in the output?

i have a scenario where there is an LOV with High Value as "Package" and TYPE="TO_NEW_PACKAGE" and i have to fetch the value of Low and there are 8 records in Low. I Have to display all the 8 records and their component cost for each record. All this should be gone as a display Message which will be output. Please let me know how to do this.
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'"; SetSearchExpr(sSearchExp); ExecuteQuery(); var isRecord = FirstRecord(); while(isRecord) { Slow = GetFieldValue("Low"); Outputs.SetProperty ("NEW_PACKAGE_PLAN",Slow); Outputs.SetProperty("ErrorCode", "00"); Outputs.SetProperty("ErrorDesc", "Success"); i = i+1; isRecord = NextRecord(); }
this is storing only 1 record... i want all the eight records to be displayed!
This should get you started
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord) {
Slow += GetFieldValue("Low");
Slow += " ";
i = i + 1;
isRecord = NextRecord();
}
Outputs.SetProperty("NEW_PACKAGE_PLAN", Slow);
Outputs.SetProperty("ErrorCode", "00");
Outputs.SetProperty("ErrorDesc", "Success");
This sample code will print the values downwards:
var boAsset = TheApplication().GetBusObject("List Of Values");
var bcAsset = boAsset.GetBusComp("List Of Values");
with (bcAsset)
{
ActivateField("Value");
var sSearchExp = "[Type]= 'AAG_TABLE_TYPE'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord)
{
Slow += GetFieldValue("Value");
Slow += "\n";
isRecord = NextRecord();
}
TheApplication().RaiseErrorText(Slow);
}
Output:
AAG Account
AAG Holdg
AAG Portf
AAG Txn
Changing Slow += "\n"; to Slow += " "; will print the values sideways.
Hope you get the trick here.

Record is not updating in a phonegap sqlite storage given in a particular query

This is the query which is update single record in a table.
Where FriendTable.tablename and other column name is define a constant file.
Values which is to update is store in Friend variable.
FriendTable.updateValues=function(Friend,successCallback,errorCallback){
var query = 'update '+ FriendTable.tablename + ' set ' + FriendTable.lat + '=?,' + FriendTable.lon + '=?,' + FriendTable.locaddr + '=?,' + FriendTable.locts + '=? where ' + FriendTable.phonenumber + " =?";
app.dbobj.transaction(function (tx) {
console.log('Update Friend record :: ' + query);
console.log('Friend data :: ' + Friend.toString());
tx.executeSql(query,[Friend.lat,Friend.lon,Friend.locaddr,Friend.locts,Friend.phonenumber],successCallback,errorCallback);
});
}

Resources