Clarity

 View Only

 How to mass update the User UserName (XOG) while leaving the UserID intact?

Pawel Krystosiak's profile image
Pawel Krystosiak posted Oct 06, 2022 05:38 PM
Dear Community Members,

I need to update users - change their UserName to match their emails (for SSO purposes). So far, their UserNames were equal to the UserID.

I have tried to use the XOG (for one user, for the starters), like:

<?xml version="1.0" encoding="UTF-8"?>
<NikuDataBus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/nikuxog_user.xsd">
  <Header version="16.0.2.861" action="write" objectType="user" externalSource="NIKU"/>
  <Users>
    <User userLanguage="English" userStatus="Active" userName="email@mailserver.com" externalId=" ">
      <PersonalInformation emailAddress="email@mailserver.com" firstName="first" lastName="last"/>
      <Resource resourceId="123456"/>
    </User>
  </Users>
</NikuDataBus>

(text in bold has been anonymized)

But when I run it, I get:
"java.lang.Exception: Resource 123456 already associated with another user. Please use an unique resourceId."

When I change the UserName and set it to the email address through the UI, it obviously works. But I have almost 1k users to update, so that would mean a lot of clicking ;)

I'd rather do it through XOG (or any other automated way...).

Thank you in advance!
Pawel
Mauro Munoz's profile image
Mauro Munoz
Hello, we have done the same thing the past week.

Here's the GEL script I used:
<gel:script xmlns:core="jelly:core" xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary" xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sql="jelly:sql" xmlns:xog="http://www.niku.com/xog"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <gel:setDataSource dbId="niku"/>
  <!-- QUERY FOR MULTIPLE RESULTS -->
  <sql:query escapeText="0" var="multipleResults">
	  <![CDATA[/*sql*/
		SELECT
		    RES.unique_name,
			RES.email,
			RES.first_name,
			RES.last_name
		FROM 
			SRM_RESOURCES RES
			
	]]>
	</sql:query>
	
  <!-- GET SESSIONID BY USERNAME -->
  <core:set value="admin" var="username"/>
	
  <core:new className="com.niku.union.security.DefaultSecurityIdentifier" var="secId"/>
  <core:invokeStatic className="com.niku.union.security.UserSessionControllerFactory" method="getInstance" var="userSessionCtrl"/>
  <core:set value="${userSessionCtrl.init(username, secId)}" var="secId"/>
  <core:set value="${secId.getSessionId()}" var="sessionID"/>
	
  <core:choose>
    <core:when test="${sessionID == null}">
      <gel:log level="ERROR">Cannot login to Clarity XOG. Check username.</gel:log>
    </core:when>
    <core:otherwise>
      <gel:log>SessionID: ${sessionID}</gel:log>
    </core:otherwise>
  </core:choose>
	
  <core:forEach items="${multipleResults.rows}" trim="true" var="row">
	
    <!-- Invoke XOG -->
    <soap:invoke endpoint="internal" var="result">
      <soap:message>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xog="http://www.niku.com/xog">
          <soapenv:Header>
            <xog:Auth>
              <xog:SessionID>${sessionID}</xog:SessionID>
            </xog:Auth>
          </soapenv:Header>
          <soapenv:Body>
			<NikuDataBus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/nikuxog_user.xsd">
				<Header action="write" externalSource="NIKU" objectType="user" version="16.0.2.861" />
				<Users>
					<User externalId=" " userName="${row.email}" oldUserName="${row.unique_name}" userLanguage="Spanish" userLocale="es" userUid="${row.unique_name}">
						<PersonalInformation emailAddress="${row.email}" firstName="${row.first_name}" lastName="${row.last_name}" />
					</User>
				</Users>
			</NikuDataBus>
          </soapenv:Body>
        </soapenv:Envelope>
      </soap:message>
    </soap:invoke>
	<!-- Check for errors -->
    <gel:set asString="true" select="$result//Statistics/@failureRecords" var="failureRecs"/>
    <core:if test="${failureRecs != '0'}">
      <gel:log level="ERROR">A Problem with the XOG happened.</gel:log>
      <gel:log level="ERROR">Caught Exception was: <gel:expr select="$result"/>
      </gel:log>
    </core:if>

  </core:forEach>
	
  <!-- LOGOUT OF XOG -->
  <soap:invoke endpoint="internal" var="logout">
    <soap:message>
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xog="http://www.niku.com/xog">
        <soapenv:Header>
          <xog:Auth>
            <xog:SessionID>${sessionID}</xog:SessionID>
          </xog:Auth>
        </soapenv:Header>
        <soapenv:Body>
          <xog:Logout/>
        </soapenv:Body>
      </soapenv:Envelope>
    </soap:message>
  </soap:invoke>
	
</gel:script>​

This effectively changes the username and to their emails. You might want to change the `userLanguage` and `userLocale` to whichever you're using.
Keep in mind that some records might fail to update, like `admin` or any other duplicate email.


Cheers,
Mauro.
Martti Kinnunen's profile image
Martti Kinnunen

Just wondering again...

Is it different from what it used to be?

See

https://community.broadcom.com/enterprisesoftware/communities/community-home/digestviewer/viewthread?GroupId=1747&MID=723799&CommunityKey=7f0cbca3-5f93-4d44-a369-1a8ce98f5578&tab=digestviewer

Mauro Munoz's profile image
Mauro Munoz
What I meant by duplicate email was, since Pawel's trying to change the usernames to their emails, it might fail if two users have the same email.
e.g:
  • User 1:
    •   username: a
    •   email: email@nowhere.com

  • User 2:
    •   username: b
    •   email: email@nowhere.com

If we first XOG User 1, its username will become email@nowhere.com.
Now, if we try to XOG User 2, it will fail since User 1 already has email@nowhere.com as its username.

The username is still the unique primary key, and Resource ID is unique.
https://techdocs.broadcom.com/us/en/ca-enterprise-software/business-management/clarity-project-and-portfolio-management-ppm-on-premise/16-0-3/reference/xml-open-gateway-xog-development/xog-object-reference/xog-user.html
https://techdocs.broadcom.com/us/en/ca-enterprise-software/business-management/clarity-project-and-portfolio-management-ppm-on-premise/16-0-3/reference/xml-open-gateway-xog-development/xog-object-reference/xog-resource.html
JP_Thompson's profile image
JP_Thompson
Hi,

When we moved to SSO, we used their assigned LAN/Network ID as their username, this removed the issue of having duplicate email and the Xog failing to update all users.

Hope this helps.

Regards