cglowe
02-08-2022Cloud Apps
Dynamic username on dashboard welcome message
I have a landing (homepage) dashboard that includes a text widget with welcome message. I would like the welcome message to include the viewer's {username} or {first name}, but am not sure the best way to accomplish this. Is there a native way through scripting? Is BloX the best route?
I think your code should work if you add a couple pieces:
widget.on('ready', function(){ var eleExists = document.getElementById("myPara"); if(!eleExists){ const para = document.createElement("p"); para.setAttribute("id", "myPara"); const node = document.createTextNode("Welcome " + prism.user.firstName + "!"); para.appendChild(node); const element = document.getElementById("editor-3"); element.appendChild(para); } })
It adds an id to your paragraph element and first checks to make sure that id doesn't exist before adding a new paragraph & text.
cglowe You can also play with blox to get the desired effect.
Blox:{ "style": "", "script": "", "title": "", "showCarousel": true, "body": [ { "type": "Container", "items": [ { "type": "ColumnSet", "columns": [ { "type": "Column", "width": "50%", "items": [ { "type": "TextBlock", "text": "❤️️ Welcome ️", "style": { "text-align": "center", "font-weight": "bold", "font-size": "24px", "margin-top": "50px", "margin-bottom": "50px", "margin-left": "50%", "text-aligment": "right" } } ] }, { "type": "Column", "width": "30%", "items": [ { "type": "TextBlock", "text": "️test", "id": "myUser", "style": { "text-align": "center", "font-weight": "bold", "font-size": "24px", "margin-top": "50px", "margin-bottom": "50px", "margin-left": "-70%", "color": "blue" } } ] } ] } ] } ], "actions": [] }
widget script:
widget.on("ready", function (w, args) { $("#myUser").text(prism.user.firstName + ' ' + prism.user.lastName) })
This is just simple example but within column set you can put any TextBlock/data you want (static text, data from elasticube etc).