const start = new Date()
const end = new Date()
start.setHours(0, 0, 0, 0)
end.setHours(23, 59, 59, 999)
console.log(start.toISOString())
console.log(end.toISOString())
[CAP] Login to CF using a bash script
Create your script file, make it executeable and add it to your .gitignore as it contains sensitive information:
touch login.sh
chmod +x login.sh
echo login.sh >> .gitignore
Open the file and paste the following:
#! /bin/bash
cf login <<!
myemail@mail.com
mypassword
1
!
With “1” you select your target space. Save your script and run it using:
./login.sh
After some time, it can happen that the default identity provider of the SAP BTP (SAP ID service) is asking for a password change. I don’t know exactly, but it seems to be every 90 days?!
The login process will fail with the following output:
$ ./scripts/login.sh
API endpoint: https://api.cf.eu10.hana.ondemand.com
Email: myemail@mail.com
Password:
Authenticating...
{"error":"invalid_grant","error_description":"User authentication failed: PASSWORD_CHANGE_REQUIRED"}
To change your password, just go to https://account.sap.com or https://accounts.sap.com/, and it should directly open the password change screen.
Update 06.09.2024: The login can now also be done by completely using the cf command.
cf login -a https://api.cf.eu10.hana.ondemand.com -o myOrg -s mySpace -u myEmail@mail.com -p myPassword
[CAP] Create and deploy bookshop sample app
Since CDS 5.9.2 this is the quickest way of creating and deploying the bookshop sample:
cds init bookshop
cd bookshop
cds add samples
cds add hana
cds add xsuaa
cds add mta
npm install
mbt build
cf deploy mta_archives/bookshop_1.0.0.mtar
[Home Assistant] Open window reminder
This automation is triggered when a window stays open for >10 minutes. It will then send a reminder every 10 minutes (max 6 times).
This post helped me to create this script.
alias: Open window reminder
description: ''
trigger:
- platform: state
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_xxx_on_off
from: 'off'
to: 'on'
for:
hours: 0
minutes: 10
seconds: 0
condition: []
action:
- repeat:
while:
- condition: state
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_xxx_on_off
state: 'on'
- condition: template
value_template: '{{ repeat.index <= 6 }}'
sequence:
- variables:
counter: '{{ repeat.index * 10 }}'
- service: telegram_bot.send_message
data:
message: Window is open for {{ counter }} minutes
- delay: '00:10:00'
mode: single
[ABAP] Include table fields in local type
Somehow I always forget the syntax for this….
TYPES: BEGIN OF ty_test.
INCLUDE TYPE z_table.
TYPES: my_new_field TYPE string,
END OF ty_test.
[Windows] Package Manager
https://just-install.github.io/
https://github.com/microsoft/winget-cli
For installing some basic software: https://ninite.com/
[Home Assistant] Control lights with multiple motion sensors
Create group of motion sensors in groups.yaml
https://www.home-assistant.io/integrations/group/
cellar_motion:
name: Cellar Presence
icon: mdi:motion-sensor
entities:
- binary_sensor.bewegungsmelder_xxx_ias_zone
- binary_sensor.bewegungsmelder_xxx_ias_zone
Next, if you have more than one light you’d like to control, create a group of lights in your configuration.yaml
https://www.home-assistant.io/integrations/light.group/
# Light Groups
light:
- platform: group
name: Cellar Lights
entities:
- light.ikea_of_sweden_tradfri_bulb_e27_ww_806lm_xxx_level_on_off
- light.ikea_of_sweden_tradfri_bulb_e27_ww_806lm_xxx_level_on_off
And finally use both in an automation
alias: My motion activated lights
description: Turn on a light when motion is detected.
trigger:
- platform: state
entity_id: group.cellar_motion
from: 'off'
to: 'on'
condition: []
action:
- service: light.turn_on
target:
entity_id: light.cellar_lights
data: {}
- wait_for_trigger:
platform: state
entity_id: group.cellar_motion
from: 'on'
to: 'off'
- delay: 120
- service: light.turn_off
target:
entity_id: light.cellar_lights
data: {}
mode: restart
max_exceeded: silent # https://www.home-assistant.io/docs/automation/modes/
[CAP] Get destination data using sap-cloud-sdk
https://sap.github.io/cloud-sdk/docs/js/features/connectivity/destination
const { getDestination } = require("@sap-cloud-sdk/connectivity")
const myDestination= await getDestination("myDestination")
if (myDestination === null) throw Error(`Destination "myDestination" not found`)
for (let key in myDestination) {
console.log(key, myDestination[key])
}
[CAP] BAS – port 4004 is already in use by another server process
If the default port 4004 is already open and you want to see what is bound to it, select View -> Find Command -> Ports Preview
Solution to kill another “watch.js” process using/blocking the port: https://answers.sap.com/questions/13016130/sap-business-application-studio-stop-running-serve.html
To archive the same in a single command use:
lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep watch.js | awk '{print $2}')
As alternative, change the default port by adding a new port in package.json to the start script, for example: “start”: “cds run –port 4003” and use npm run start instead of cds watch.
Update 20.02.2023: Just had the problem again due to a VPN disconnect. But this time I had an application running using cds run
. Therefore, I had to change the command from watch.js
to cds.js
:
lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep cds.js | awk '{print $2}')
Update 10.05.2023: A better approach seems to be killing the node process. This should work in both situation.
lwctl -c basic-tools kill -9 $(lwctl -c basic-tools ps aux | grep node | awk '{print $2}')
Update 29.02.2024: With the BAS migration to Code – OSS the previous commands were not working anymore, but this new command seems to work:
kill -9 $(ps aux | grep cds.js | awk '{print $2}')
# or
kill -9 $(ps aux | grep cds-dk | awk '{print $2}')
[CAP] Query teamMembersSize from SuccessFactors
const sfsfSrv = await cds.connect.to('sfsf')
// Option 1: Query Notation
const response = await sfsfSrv.run(SELECT`teamMembersSize`.from`User`.where`userId = ${req.user.id}`)
console.log("option 1: " + response[0].teamMembersSize)
// Option 2: HTTP method-style
const response2 = await sfsfSrv.get(`/User('${req.user.id}')/teamMembersSize/$value`)
console.log("option 2: " + response2)