<?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 Business Rule to Assign Role on Insert into sys_user table with conditions in ServiceNow AI Platform forum</title>
    <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699205#M191650</link>
    <description>&lt;P&gt;I have a request alter code for assigning as specific role to a user when inserted into the sys_user table. My current code works as expected but it's applying to "all users" inserted and now I need it to filter out specific records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {

var appRole = new GlideRecord('sys_user_has_role');
appRole.initialize();
appRole.user = current.sys_id;
appRole.role = 'sys_id_of_role'; // role sys_id for xyz appRole.insert();

})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;I need this to filter out users where -&lt;/P&gt;&lt;P&gt;1. sys_user - Employee number is not empty, and Class is User&lt;/P&gt;&lt;P&gt;2. sys_user_group - User is not a member of xyz group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I incorporate these requirements into my current code?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2023 17:44:41 GMT</pubDate>
    <dc:creator>Scott Megargee</dc:creator>
    <dc:date>2023-10-11T17:44:41Z</dc:date>
    <item>
      <title>Business Rule to Assign Role on Insert into sys_user table with conditions</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699205#M191650</link>
      <description>&lt;P&gt;I have a request alter code for assigning as specific role to a user when inserted into the sys_user table. My current code works as expected but it's applying to "all users" inserted and now I need it to filter out specific records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function executeRule(current, previous /*null when async*/) {

var appRole = new GlideRecord('sys_user_has_role');
appRole.initialize();
appRole.user = current.sys_id;
appRole.role = 'sys_id_of_role'; // role sys_id for xyz appRole.insert();

})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;I need this to filter out users where -&lt;/P&gt;&lt;P&gt;1. sys_user - Employee number is not empty, and Class is User&lt;/P&gt;&lt;P&gt;2. sys_user_group - User is not a member of xyz group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I incorporate these requirements into my current code?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 17:44:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699205#M191650</guid>
      <dc:creator>Scott Megargee</dc:creator>
      <dc:date>2023-10-11T17:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Business Rule to Assign Role on Insert into sys_user table with conditions</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699216#M191651</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't see a reason why to change your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you looked at changing the &lt;U&gt;&lt;STRONG&gt;conditions&lt;/STRONG&gt;&lt;/U&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 17:50:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699216#M191651</guid>
      <dc:creator>Mark Roethof</dc:creator>
      <dc:date>2023-10-11T17:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Business Rule to Assign Role on Insert into sys_user table with conditions</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699218#M191652</link>
      <description>&lt;P&gt;You might also consider newer techniques for requirements like these... Flow Designer. Zero code involved when I look at what you are asking.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 17:52:04 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699218#M191652</guid>
      <dc:creator>Mark Roethof</dc:creator>
      <dc:date>2023-10-11T17:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Business Rule to Assign Role on Insert into sys_user table with conditions</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699220#M191653</link>
      <description>&lt;P&gt;Basically, I only want to run the code if a record inserted into sys user table meets the new conditions I noted. I don't really have a lot of flexibility when it comes to changing the conditions/requirements for when the code should run.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 17:53:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699220#M191653</guid>
      <dc:creator>Scott Megargee</dc:creator>
      <dc:date>2023-10-11T17:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Business Rule to Assign Role on Insert into sys_user table with conditions</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699226#M191654</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/355770"&gt;@Scott Megargee&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;For your filter conditions you can first query on&amp;nbsp;sys_user_grmember table in this table you add a filter of your group and also dot walk using user fields in your case employee number and class since user is reference on this column, at the same time you can use the sample encoded query to build your query "user.active=true^user.cityISNOTEMPTY^group=e948597ef7ecf810ec1c41b84851e0a7"&lt;/P&gt;&lt;P&gt;If this query returns records then you can proceed ahead with your code of assigning the role to the intended user.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 17:56:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699226#M191654</guid>
      <dc:creator>Anubhav24</dc:creator>
      <dc:date>2023-10-11T17:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Business Rule to Assign Role on Insert into sys_user table with conditions</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699227#M191655</link>
      <description>&lt;P&gt;I don't understand, why wouldn't you have flexibility in changing the conditions of the business rule? That would even be a &lt;U&gt;&lt;STRONG&gt;best practice&lt;/STRONG&gt;&lt;/U&gt;, over doing such in your script since your script would simply trigger unnecessary.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 18:01:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/business-rule-to-assign-role-on-insert-into-sys-user-table-with/m-p/2699227#M191655</guid>
      <dc:creator>Mark Roethof</dc:creator>
      <dc:date>2023-10-11T18:01:47Z</dc:date>
    </item>
  </channel>
</rss>

