AustinMerlo
6 years agoQrew Member
Help with pulling User Role info with Javascript
Goal/Background: I have a table that lists all the users of my application and I would like to be able to add each user's Role to their record.
I was able to pull the user role info via API_GetUserRole and parse that info with a simple javascript snippet that writes to the console.
Question: How do I write the output of the javascript to the field or another field instead? Is there a way to do this automatically so when a new user is added the role is pulled?
I don't have much knowledge with javascript so any information is greatly appreciated.
This is what I have so far in my URL formula field:
------------------------------
Best,
Austin
------------------------------
I was able to pull the user role info via API_GetUserRole and parse that info with a simple javascript snippet that writes to the console.
Question: How do I write the output of the javascript to the field or another field instead? Is there a way to do this automatically so when a new user is added the role is pulled?
I don't have much knowledge with javascript so any information is greatly appreciated.
This is what I have so far in my URL formula field:
var Text ticket = "TicketHere"; var Text usrID = "userIDHere"; var Text apppToken = "appTokenHere"; var Text urlRole = URLRoot() & "db/" & "bpeu9wky6" & "?a=API_GetUserRole&ticket=" &$ticket& "&apptoken=" & $apppToken &"&inclgrps=1&userid="& $usrID ; "javascript: " & "$.get('" & $urlRole & "',function(data,success) {" & "console.log(data);" & "var user = data.getElementsByTagName('role')[0].getElementsByTagName('name')[0].innerHTML;" & "console.log(user);" & "});"
------------------------------
Best,
Austin
------------------------------