<?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>question Need to create AD account with lastname, firstname. in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/need-to-create-ad-account-with-lastname-firstname/m-p/3019678#M617</link>
    <description>&lt;P&gt;While creating AD account it's creating account with first initial last name same as Samaccount name, but I want to create account with lastname, firstname,&lt;/P&gt;&lt;P&gt;When I replace CN with lastname, firstname , it's showing error as dn syntax invalid&amp;nbsp;&lt;/P&gt;&lt;P&gt;How we can achieve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Aug 2024 06:26:06 GMT</pubDate>
    <dc:creator>kumbharh</dc:creator>
    <dc:date>2024-08-16T06:26:06Z</dc:date>
    <item>
      <title>Need to create AD account with lastname, firstname.</title>
      <link>https://www.servicenow.com/community/community-central-forum/need-to-create-ad-account-with-lastname-firstname/m-p/3019678#M617</link>
      <description>&lt;P&gt;While creating AD account it's creating account with first initial last name same as Samaccount name, but I want to create account with lastname, firstname,&lt;/P&gt;&lt;P&gt;When I replace CN with lastname, firstname , it's showing error as dn syntax invalid&amp;nbsp;&lt;/P&gt;&lt;P&gt;How we can achieve this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 06:26:06 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/need-to-create-ad-account-with-lastname-firstname/m-p/3019678#M617</guid>
      <dc:creator>kumbharh</dc:creator>
      <dc:date>2024-08-16T06:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need to create AD account with lastname, firstname.</title>
      <link>https://www.servicenow.com/community/community-central-forum/need-to-create-ad-account-with-lastname-firstname/m-p/3019697#M618</link>
      <description>&lt;P&gt;In ServiceNow, when you're creating an Active Directory (AD) account through an integration or automation, and you want to format the &lt;CODE&gt;CN&lt;/CODE&gt; (Common Name) as "lastname, firstname", you need to ensure the DN (Distinguished Name) is properly formatted to avoid syntax errors.&lt;/P&gt;
&lt;H3&gt;Steps to Achieve This in ServiceNow:&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Escape the Comma in CN:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When constructing the &lt;CODE&gt;CN&lt;/CODE&gt; in your ServiceNow script, you need to escape the comma to conform to AD's DN requirements. For example, if you're using a script in a flow or a business rule:
&lt;DIV class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"&gt;
&lt;DIV class="overflow-y-auto p-4" dir="ltr"&gt;&lt;CODE class="!whitespace-pre hljs language-javascript"&gt;&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; lastName = &lt;SPAN class="hljs-string"&gt;"Doe"&lt;/SPAN&gt;;
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; firstName = &lt;SPAN class="hljs-string"&gt;"John"&lt;/SPAN&gt;;
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; cn = lastName + &lt;SPAN class="hljs-string"&gt;"\\, "&lt;/SPAN&gt; + firstName;
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; dn = &lt;SPAN class="hljs-string"&gt;"CN="&lt;/SPAN&gt; + cn + &lt;SPAN class="hljs-string"&gt;",OU=Users,DC=domain,DC=com"&lt;/SPAN&gt;;
&lt;/CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Creating the User in AD:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use the &lt;CODE&gt;cn&lt;/CODE&gt; variable when constructing the DN in your REST API call or LDAP operation. Here's a basic example of how this might look in a script:
&lt;DIV class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium"&gt;
&lt;DIV class="overflow-y-auto p-4" dir="ltr"&gt;&lt;CODE class="!whitespace-pre hljs language-javascript"&gt;&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; requestBody = {
    &lt;SPAN class="hljs-string"&gt;"attributes"&lt;/SPAN&gt;: {
        &lt;SPAN class="hljs-string"&gt;"samAccountName"&lt;/SPAN&gt;: &lt;SPAN class="hljs-string"&gt;"jdoe"&lt;/SPAN&gt;,
        &lt;SPAN class="hljs-string"&gt;"userPrincipalName"&lt;/SPAN&gt;: &lt;SPAN class="hljs-string"&gt;"jdoe@domain.com"&lt;/SPAN&gt;,
        &lt;SPAN class="hljs-string"&gt;"cn"&lt;/SPAN&gt;: cn,
        &lt;SPAN class="hljs-string"&gt;"sn"&lt;/SPAN&gt;: lastName,
        &lt;SPAN class="hljs-string"&gt;"givenName"&lt;/SPAN&gt;: firstName,
        &lt;SPAN class="hljs-comment"&gt;// Add other required attributes here&lt;/SPAN&gt;
    },
    &lt;SPAN class="hljs-string"&gt;"dn"&lt;/SPAN&gt;: dn
};

&lt;SPAN class="hljs-comment"&gt;// Assuming you're making a REST call to your AD integration&lt;/SPAN&gt;
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; response = sn_ws.&lt;SPAN class="hljs-title class_"&gt;RESTMessageV&lt;/SPAN&gt;2(&lt;SPAN class="hljs-string"&gt;'AD Create User'&lt;/SPAN&gt;, &lt;SPAN class="hljs-string"&gt;'post'&lt;/SPAN&gt;);
response.&lt;SPAN class="hljs-title function_"&gt;setRequestBody&lt;/SPAN&gt;(&lt;SPAN class="hljs-title class_"&gt;JSON&lt;/SPAN&gt;.&lt;SPAN class="hljs-title function_"&gt;stringify&lt;/SPAN&gt;(requestBody));
&lt;SPAN class="hljs-keyword"&gt;var&lt;/SPAN&gt; responseObj = response.&lt;SPAN class="hljs-title function_"&gt;execute&lt;/SPAN&gt;();
&lt;/CODE&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;&lt;STRONG&gt;Handle the Response:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Ensure your script handles any potential errors from AD, especially regarding DN syntax issues, so you can troubleshoot if the formatting needs adjustment.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;H3&gt;Important Considerations:&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Attribute Validation&lt;/STRONG&gt;: Ensure that other required attributes in the AD creation process are correctly provided and formatted.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Error Handling&lt;/STRONG&gt;: Add error handling to catch and log any issues with the DN syntax or other problems in the creation process.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 16 Aug 2024 06:41:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/need-to-create-ad-account-with-lastname-firstname/m-p/3019697#M618</guid>
      <dc:creator>Ravi Gaurav</dc:creator>
      <dc:date>2024-08-16T06:41:44Z</dc:date>
    </item>
  </channel>
</rss>

