Picture of Bernd 5977
Registered 3 years 123 days
Bernd 5977 Thursday, 24 February 2022, 12:03 PM
How do I get user's data in the xxx_webapp.js ?
Hi together,

I have maybe a simple question...

When I want to know for example the phoneNumber or the displayName of the loggedIn user, how do I get this information in the xxx_webapp.js?

I assume I have to consume this api "com.innovaphone.client"?

Like:
var clientApi = start.consumeApi("com.innovaphone.client");

But then, how do I go forward to get/request the phoneNumber or the displayName?

Best regards
Bernd
Andreas Fink
Moderator Registered 13 years 110 days
Andreas Fink (innovaphone) Thursday, 24 February 2022, 01:57 PM
1 of 1 users consider this post helpful
Re: How do I get user's data in the xxx_webapp.js ?
Hello Bernd,

the client APIs provide additional information via ApiUpdate messages.


Here a short example, how to access this info, whet it gets updated:

this.clientApi = start.consumeApi("com.innovaphone.client");

window.addEventListener("message", onwindowmessage);

function onwindowmessage(msg) {
const obj = JSON.parse(msg.data);

if (obj.mt === "ApiUpdate") {
console.log(obj);

console.warn(obj.apis["com.innovaphone.client"]["@client"]["model"]["user"]["num"]);
console.warn(obj.apis["com.innovaphone.client"]["@client"]["model"]["user"]["dn"]);
}
}



Best Regards
Andreas Fink
Picture of Bernd 5977
Registered 3 years 123 days
Bernd 5977 Friday, 25 February 2022, 09:00 AM
Re: How do I get user's data in the xxx_webapp.js ?
Hi Andreas,

ok, when it's updated I can get this over this EventListener.

But how do I get the data from the actual logged in user, when nothing has changed?
So I want to know the data as it is currently?


Best regards
Bernd
Picture of Bernd 5977
Registered 3 years 123 days
Bernd 5977 Friday, 25 February 2022, 10:20 AM
Re: How do I get user's data in the xxx_webapp.js ?
Hi Andreas,

I have try it out - I get the phone number when the app is startet.
Exactly what I want smile

Thanks.

Best regards
Andreas Fink
Moderator Registered 13 years 110 days
Andreas Fink (innovaphone) Friday, 25 February 2022, 10:27 AM in response to Bernd 5977
1 of 1 users consider this post helpful
Re: How do I get user's data in the xxx_webapp.js ?
If you look at this from reactive programming paradigm, this is exact the way to get the info.

You can use a global variable to store the value and update it every time the value has been changed changed.

Best Regards
Andreas Fink
← You can define your color theme preference here