I am using javascript to read an XML, and create an envelope before storing in database. While creating headers, I need to populate the element "created-by" with the value of current user.
let user = xdmp.getCurrentUser()
I tried something like below, but its not replacing the variable with the value.
let a = xdmp.unquote('<created-by>{user}</created-by>')
How could I pass variable to XML using Javascript?
If you want to use JavaScript template literals, then change the single quote '
to a back-tick `
, and put a $
in front of the curly braces marking the variable placeholder:
let a = xdmp.unquote(`<created-by>${user}</created-by>`)