JavaScript outside of Dundas

Hi,

Perhaps an easy question. I have a few JavaScript apps that are called but are written outside of Dundas. I want to actually get the username of the person logged into Dundas in one of those scripts, but I’m not sure what I’d need to do to be able to call it.

Writing scripts in Dundas, I’d use something like:

var name = dundas.context.currentSession.accountDisplayName;

Pretty sure I need to import a library or something, just not sure of the command.

Sorry, rookie question. Coding isn’t my strong suit, though I’m picking it up.

Thx.

Not sure from your question what you are doing?

If you are calling an external JS app from Dundas, can you not pass the username to the app when you call it?

So, I set-up a Node.Js server, w/ Express & am using it to write data back to the MSSQL database on the same server, but under it’s own database. I am going to write & read to that database, but this is new territory for me so I’m mostly going from different things I’ve found on the internet.

I’ve got an HTML frame on the page in Dundas, that links to an index.html on the local server & which is where the other scripts to write to the database are. Here’s the script I use to pass data to the server, but you’ll see the username is being pulled from a form & I’m not sure how to pass it from Dundas to the script:

$.getJSON('https://ipapi.co/json/', function(data) {

const CreateUser = document.querySelector('.CreateUser')
CreateUser.addEventListener('submit', (e) => {
  e.preventDefault()
  const username = CreateUser.querySelector('.username').value;
  const termstatus = "1";
  const ip = data.ip;
  const city = data.city;
  const region_code = data.region_code;
  const country_name = data.country_name;
  const latitude = data.latitude;
  const longitude = data.longitude;
  post('/createUser', { username, termstatus, ip, city, region_code, 

country_name, latitude, longitude })
})
	function post (path, data) {
return window.fetch(path, {
method: 'POST',
headers: {
  'Accept': 'application/json',
  'Content-Type': 'application/json'
},
body: JSON.stringify(data)
  })
}

});

Thx.

Have the page take a parameter in the URL and put the Dundas user name in it then have the Script take that in as a parameter or read it form the page.

that my best guess on how to solve this,

Looks like the above is the key line to do this.

What happens if you do

const username = dundas.context.currentSession.accountDisplayName;

That’ll give you your public-facing username associated with the logged on Dundas user. It should be the same name as what you see on the default home page of your instance. To change this for an account, you want to modify the Display Name account field.

So, I get an error in the console when I try to use that. Keep in mind, this is a separate javascript file, not code that is sitting in Dundas. The line of code works fine if I attach it to something in Dundas, but when called in this javascript, which resides outside of Dundas, the console issues a failure at this line.

I was thinking that maybe I had to import the Dundas libraries or something, in the code - though James suggestion may work with some tweaking.

That is why i suggested putting a parameter in the URL that has the user name.
Have you looked into this?

1 Like

Plan to do research into that today. It’s a good suggestion!