<?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 UI action condition to check whether the user in the owned by field has role hl_help in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697194#M354120</link>
    <description>&lt;P&gt;I want to display help button in incident form only when the user in the owned by field has role hl_help.&lt;/P&gt;&lt;P&gt;the owned by field is in incident table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just tried this condition but it doesnt work&lt;/P&gt;&lt;P&gt;current.u_owned_by.role=="hl_help"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Tue, 06 Oct 2015 04:28:58 GMT</pubDate>
    <dc:creator>anto</dc:creator>
    <dc:date>2015-10-06T04:28:58Z</dc:date>
    <item>
      <title>UI action condition to check whether the user in the owned by field has role hl_help</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697194#M354120</link>
      <description>&lt;P&gt;I want to display help button in incident form only when the user in the owned by field has role hl_help.&lt;/P&gt;&lt;P&gt;the owned by field is in incident table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just tried this condition but it doesnt work&lt;/P&gt;&lt;P&gt;current.u_owned_by.role=="hl_help"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2015 04:28:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697194#M354120</guid>
      <dc:creator>anto</dc:creator>
      <dc:date>2015-10-06T04:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: UI action condition to check whether the user in the owned by field has role hl_help</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697195#M354121</link>
      <description>&lt;P&gt;Hi Joshwa,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Is the role field populated on the sys_user table. The best way would be to write a script include and then return true or false based on the validation.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Please let me know if you have any questions.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Oct 2015 04:34:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697195#M354121</guid>
      <dc:creator>Pradeep Sharma</dc:creator>
      <dc:date>2015-10-06T04:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: UI action condition to check whether the user in the owned by field has role hl_help</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697196#M354122</link>
      <description>&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14441070535388168 jive_text_macro jive_macro_code" jivemacro_uid="_14441070535388168"&gt;&lt;SPAN style="color: #666666; font-family: arial, sans-serif; font-size: 13px; background-color: #f6f6f6;"&gt;current.u_owned_by.role=="hl_help"&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;That won't work as Roles are stored in the many to many table "&lt;SPAN style="color: #881280; font-family: monospace; font-size: 13px;"&gt;sys_user_has_role".&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Luckily enough ServiceNow provide us with the GlideUser API to do this without needed to query the database directly.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;See &lt;A href="http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0" title="http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0"&gt;http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Line by line:&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14441070535337328 jive_text_macro jive_macro_code" jivemacro_uid="_14441070535337328"&gt;
&lt;P&gt;var glideUser = gs.getUser();&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;var ownedByUser = glideUser&lt;/SPAN&gt;. ­getUserByID&lt;SPAN class="br0" style="color: #009900;"&gt;(&lt;/SPAN&gt; ­&lt;SPAN style="color: #666666; font-family: arial, sans-serif; font-size: 13px; background-color: #f6f6f6;"&gt;current.u_owned_by.user_name&lt;/SPAN&gt;&lt;SPAN class="br0" style="color: #009900;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="sy0" style="color: #339933;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="color: #339933; font-size: 13.3333px;"&gt;var hasRole = ownedByUser.hasRole('hl_help');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;As Pradeep has suggested, throw this in a script include and call it in your condition field.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Script Include&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;A href="http://wiki.servicenow.com/index.php?title=Script_Includes" title="http://wiki.servicenow.com/index.php?title=Script_Includes"&gt;Script Includes - ServiceNow Wiki&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;You could then end up with something like&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;STRONG&gt;Script Include&lt;/STRONG&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14441070535263539" jivemacro_uid="_14441070535263539" modifiedtitle="true"&gt;
&lt;P&gt;UIActionConditionHelper.userHasRole = function(role, user_name) {&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; var glideUser = gs.getUser();&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; var ownedByUser = glideUser. ­getUserByID(user_name);&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; var hasRole = ownedByUser.hasRole(role);&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt; &amp;nbsp; return hadRole;&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;};&lt;/P&gt;&lt;BR /&gt;
&lt;P&gt;var UIActionConditionHelper = Class.create();&lt;/P&gt;&lt;BR /&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;STRONG&gt;UIAction Condition&lt;/STRONG&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_14441070535178844 jive_text_macro jive_macro_code" jivemacro_uid="_14441070535178844"&gt;
&lt;P&gt;UIActionConditionHelper.userHasRole('hl_help',current.owned_by.user_name);&lt;/P&gt;&lt;BR /&gt;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Oct 2015 04:47:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697196#M354122</guid>
      <dc:creator>paulmorris</dc:creator>
      <dc:date>2015-10-06T04:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: UI action condition to check whether the user in the owned by field has role hl_help</title>
      <link>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697197#M354123</link>
      <description>&lt;P&gt;Thank you Pradeep/Paul.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Great Learning...&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Everyday you guys are teaching me something&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Thanks for your wonderfull help&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Cheers..&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Oct 2015 05:18:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/ui-action-condition-to-check-whether-the-user-in-the-owned-by/m-p/1697197#M354123</guid>
      <dc:creator>anto</dc:creator>
      <dc:date>2015-10-06T05:18:26Z</dc:date>
    </item>
  </channel>
</rss>

