Display User Name & ID
We are using Sharepoint Forms on our WA site and using Power Automate to perform functions when the form is submitted. We would love a way to capture the WA User ID to do this (currently the member must look it up and enter it into the appropriate form field). In 2017 Team CMS posted the snippet below to display the member name. It still works. I've been trying to guess the variable name for the ID, but so far haven't guessed correctly. Does anyone know the name of that variable?
Team CMS commented Dec 4, 2017
For this purpose you can use following snippet in 2 ways:
<script type="text/javascript">(function() { var container = document.querySelector('.loggedName') || document.querySelector('.loginBoxProfileLink'); if (container) { document.write(container.innerText.replace(/[\n\r]/g, '') || 'Guest'); } else { document.write('<div class="userClass_MemberName"></div>'); WA.PageParsed(function() { var container = document.querySelector('.loggedName') || document.querySelector('.loginBoxProfileLink'), out = document.querySelector('.userClass_MemberName'); if (out) { out.innerHTML = (container ? container.innerText.replace(/[\n\r]/g, '') || 'Guest' : 'Guest'); }}, window);}})();</script>
-
Mike Leroux commented
Hey there! I'm afraid user Id is not readily contained on the public side. In order to obtain the userId, you would need to incorporate a call to our members API endpoint '/sys/api/publicview/v1/accounts/<yourAccountId>/contacts/me'. Response from this endpoint contains information about the user, such as email, userId (which is what you are looking for), name, and other basic information.
We have an example ajax call here: https://gethelp.wildapricot.com/en/articles/1705-working-with-api-from-javascript. You would of course need to replace in the code where it says '58293' with your account ID, and where it says "APPLICATION_CLIENT_ID" with a valid client Id from your authorized applications.
For example:
$.ajax({
url: "/sys/api/v2/accounts/<yourAccountId>/contacts/me",
type: "GET",
dataType: "json",
cache: false,
async: true,
headers: { "clientId": "APPLICATION_CLIENT_ID" },
success: function (data, textStatus, jqXhr) {
alert("Current contact user Id:" + data.Id);},
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus + " (" + jqXHR.status + ") : " + errorThrown);}
});This code could be inserted into a Custom HTML gadget, see https://gethelp.wildapricot.com/en/articles/408, and you could modify it further so that it changes the contents of a content gadget or something similar, instead of simply throwing an alert.
Since this does dive a bit into our API, I would suggest taking a look at some our documentation:
https://gethelp.wildapricot.com/en/articles/180-authorizing-external-applications
https://gethelp.wildapricot.com/en/articles/1610-contacts-member-api-call.I hope that helps.