<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to update ExternalIdentifier of a user in sas Management console through code in Administration and Deployment</title>
    <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-update-ExternalIdentifier-of-a-user-in-sas-Management/m-p/934548#M28690</link>
    <description>&lt;P&gt;Assuming you have a table of users and their desired Identifier values (here I'm creating the table work.users manually), you could do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create a data set of users and their desired external identity values. */
data work.users;
length user identifier $ 255;
input user $ identifier $;
datalines;
sasadm 12345
sasdemo 67890
;;
run;

/* DATA step to update these objects. */
data _null_;
	/* Initialize some variables. */
	length type id $ 50 uri extid $ 255;
	call missing(type,id,uri,extid);
	/* Read in the source data set. */
	set work.users;
	/* Define a query to find the ExternalIdentity object associated with that user. */
	obj="omsobj:ExternalIdentity?ExternalIdentity[OwningObject/Person[@Name='"||trim(user)||"']]";
	rc=metadata_resolve(obj,type,id);
	/* If one (and only one) is found... */
	if rc = 1 then do;
		put "NOTE: Found 1 external identity for user " user ;
		/* Get the URI for the object. */
		rc=metadata_getnobj(obj,1,uri);
		/* Pull the existing identifier value. */
		rc=metadata_getattr(uri,"Identifier",extid);
		/* Only take action if the existing value does not match the desired value. */
		if extid ne identifier then do;
			put "NOTE: Identifier does not match table." extid= identifier=;
			put "NOTE- Setting attribute to value in table.";
			/* I've commented out the line that writes to metadata and replaced it with rc=0 to simulate a successful write. */
			/* To activate this code, uncomment the metadata_setattr function and comment out the rc=0. */
			*rc=metadata_setattr(uri,"Identifier",identifier); rc=0;
			if rc=0 then put "NOTE: Attribute updated successfully";
			else put "ERROR: Failed to update attribute for user " user rc=;
		end;
		else put "NOTE: No action needed, external id already matches desired value. " extid= identifier=;
	end;
	else put "NOTE: Taking no action. Found " rc "external identities for user " user;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Jul 2024 14:13:35 GMT</pubDate>
    <dc:creator>gwootton</dc:creator>
    <dc:date>2024-07-03T14:13:35Z</dc:date>
    <item>
      <title>How to update ExternalIdentifier of a user in sas Management console through code</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-update-ExternalIdentifier-of-a-user-in-sas-Management/m-p/934513#M28687</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;
&lt;P&gt;I need to delete externalidentifier of all users which are in SAS Metadata mentioned in MDUCHGVERRORS table.&lt;/P&gt;
&lt;P&gt;After that i need to update externalidentifiers of all users which are in MDUCHGVERRORS to SAS Metadata of users.&lt;/P&gt;
&lt;P&gt;Manually updating for 500 users is a hectic task and i tried to skip the comparison between AD and Metadata but not helping.&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Sandeep&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 05:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-update-ExternalIdentifier-of-a-user-in-sas-Management/m-p/934513#M28687</guid>
      <dc:creator>sandeep_reddy</dc:creator>
      <dc:date>2024-07-03T05:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to update ExternalIdentifier of a user in sas Management console through code</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/How-to-update-ExternalIdentifier-of-a-user-in-sas-Management/m-p/934548#M28690</link>
      <description>&lt;P&gt;Assuming you have a table of users and their desired Identifier values (here I'm creating the table work.users manually), you could do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create a data set of users and their desired external identity values. */
data work.users;
length user identifier $ 255;
input user $ identifier $;
datalines;
sasadm 12345
sasdemo 67890
;;
run;

/* DATA step to update these objects. */
data _null_;
	/* Initialize some variables. */
	length type id $ 50 uri extid $ 255;
	call missing(type,id,uri,extid);
	/* Read in the source data set. */
	set work.users;
	/* Define a query to find the ExternalIdentity object associated with that user. */
	obj="omsobj:ExternalIdentity?ExternalIdentity[OwningObject/Person[@Name='"||trim(user)||"']]";
	rc=metadata_resolve(obj,type,id);
	/* If one (and only one) is found... */
	if rc = 1 then do;
		put "NOTE: Found 1 external identity for user " user ;
		/* Get the URI for the object. */
		rc=metadata_getnobj(obj,1,uri);
		/* Pull the existing identifier value. */
		rc=metadata_getattr(uri,"Identifier",extid);
		/* Only take action if the existing value does not match the desired value. */
		if extid ne identifier then do;
			put "NOTE: Identifier does not match table." extid= identifier=;
			put "NOTE- Setting attribute to value in table.";
			/* I've commented out the line that writes to metadata and replaced it with rc=0 to simulate a successful write. */
			/* To activate this code, uncomment the metadata_setattr function and comment out the rc=0. */
			*rc=metadata_setattr(uri,"Identifier",identifier); rc=0;
			if rc=0 then put "NOTE: Attribute updated successfully";
			else put "ERROR: Failed to update attribute for user " user rc=;
		end;
		else put "NOTE: No action needed, external id already matches desired value. " extid= identifier=;
	end;
	else put "NOTE: Taking no action. Found " rc "external identities for user " user;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jul 2024 14:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/How-to-update-ExternalIdentifier-of-a-user-in-sas-Management/m-p/934548#M28690</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2024-07-03T14:13:35Z</dc:date>
    </item>
  </channel>
</rss>

