<?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 Want to write script for the below use case in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130345#M1835</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&amp;lt;p&amp;gt;want to write a script which will allow only the “ requested by “ . “ assigned to “ and “ Change manager role” users to edit the close code fields, even for the admin users that field should be read-only , if the admin user is the requested by / assigned to then only during&amp;nbsp; that time they should be able to edit it.&amp;lt;/p&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2024 04:41:03 GMT</pubDate>
    <dc:creator>BoyaGaneshkumar</dc:creator>
    <dc:date>2024-12-18T04:41:03Z</dc:date>
    <item>
      <title>Want to write script for the below use case</title>
      <link>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130345#M1835</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;lt;p&amp;gt;want to write a script which will allow only the “ requested by “ . “ assigned to “ and “ Change manager role” users to edit the close code fields, even for the admin users that field should be read-only , if the admin user is the requested by / assigned to then only during&amp;nbsp; that time they should be able to edit it.&amp;lt;/p&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 04:41:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130345#M1835</guid>
      <dc:creator>BoyaGaneshkumar</dc:creator>
      <dc:date>2024-12-18T04:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write script for the below use case</title>
      <link>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130363#M1836</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/554909"&gt;@BoyaGaneshkumar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can use field level WRITE ACL and use advanced script section&lt;/P&gt;
&lt;P&gt;Ensure admin overrides is unchecked&lt;/P&gt;
&lt;P&gt;Something like this in script&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;var userId = gs.getUserID();
var isRequestedBy = (current.requested_by == userId);
var isAssignedTo = (current.assigned_to == userId);
var isChangeManager = gs.hasRole('change_manager');

answer = isRequestedBy || isAssignedTo || isChangeManager;&lt;/LI-CODE&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 04:57:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130363#M1836</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2024-12-18T04:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write script for the below use case</title>
      <link>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130377#M1838</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/554909"&gt;@BoyaGaneshkumar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create write ACL with admin override unchecked, use below code in your ACL script.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Allow write access if the user is the requested_by, assigned_to, or has the 'change_manager' role
(function() {
    // Get the current user
    var currentUser = gs.getUserID();

    // Check if the user is the "requested by"
    if (current.requested_by == currentUser) {
        return true;
    }

    // Check if the user is the "assigned to"
    if (current.assigned_to == currentUser) {
        return true;
    }

    // Check if the user has the 'change_manager' role
    if (gs.hasRoleExactly('change_manager')) {
        return true;
    }

    // Deny access by default
    return false;
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Runjay Patel - ServiceNow Solution Architect&lt;BR /&gt;YouTube: &lt;A href="https://www.youtube.com/@RunjayP" target="_blank"&gt;https://www.youtube.com/@RunjayP&lt;/A&gt;&lt;BR /&gt;LinkedIn: &lt;A href="https://www.linkedin.com/in/runjay" target="_blank"&gt;https://www.linkedin.com/in/runjay&lt;/A&gt;&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 05:14:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130377#M1838</guid>
      <dc:creator>Runjay Patel</dc:creator>
      <dc:date>2024-12-18T05:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write script for the below use case</title>
      <link>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130416#M1840</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/554909"&gt;@BoyaGaneshkumar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition to creating ACL's, UI policy and data policy could be another way to meet the requirements.&lt;/P&gt;&lt;P&gt;If you want to restrict users from editing the &lt;STRONG&gt;Close Code&lt;/STRONG&gt; field on the form, you can achieve this using a &lt;STRONG&gt;UI Policy&lt;/STRONG&gt;.&lt;/P&gt;&lt;H3&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;Steps to Implement on Form:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Create a UI Policy:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Navigate to &lt;STRONG&gt;System UI &amp;gt; UI Policies&lt;/STRONG&gt; and create a new UI Policy on the &lt;STRONG&gt;Change Request&lt;/STRONG&gt; table.&lt;/LI&gt;&lt;LI&gt;Add a condition that always evaluates to true (e.g., state is not empty).&lt;/LI&gt;&lt;LI&gt;Set the &lt;STRONG&gt;Close Code&lt;/STRONG&gt; field to be &lt;STRONG&gt;read-only&lt;/STRONG&gt; by default.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Add a UI Policy Script:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Use the following script to dynamically evaluate user permissions and control the editability of the field:&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function executeRule() {
    var canEdit = false;
    var userSysId = g_user.userID;
    var requestedBy = g_form.getValue('requested_by');
    var assignedTo = g_form.getValue('assigned_to');

    // Allow users in the "Change Manager" role to edit
    if (g_user.hasRole('change_manager')) {
        canEdit = true;
    }

    // Allow users if they are the requested_by or assigned_to
    if (userSysId === requestedBy || userSysId === assignedTo) {
        canEdit = true;
    }

    // Set the read-only state of the Close Code field
    g_form.setReadonly('close_code', !canEdit);
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;For List View:&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;If you want to enforce the same restrictions in the &lt;STRONG&gt;list view&lt;/STRONG&gt;, you can use a &lt;STRONG&gt;Data Policy&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Create a &lt;STRONG&gt;Data Policy&lt;/STRONG&gt; on the &lt;STRONG&gt;Change Request&lt;/STRONG&gt; table.&lt;/LI&gt;&lt;LI&gt;Set the &lt;STRONG&gt;Close Code&lt;/STRONG&gt; field to &lt;STRONG&gt;read-only&lt;/STRONG&gt; by default.&lt;/LI&gt;&lt;LI&gt;Add conditions to make it editable only for:&lt;UL&gt;&lt;LI&gt;The &lt;STRONG&gt;Requested By&lt;/STRONG&gt; user.&lt;/LI&gt;&lt;LI&gt;The &lt;STRONG&gt;Assigned To&lt;/STRONG&gt; user.&lt;/LI&gt;&lt;LI&gt;Users with the &lt;STRONG&gt;Change Manager&lt;/STRONG&gt; role.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;&lt;STRONG&gt;Outcome:&lt;/STRONG&gt;&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;The &lt;STRONG&gt;Close Code&lt;/STRONG&gt; field will be &lt;STRONG&gt;read-only&lt;/STRONG&gt; for all users except:&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Requested By&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Assigned To&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Users with the &lt;STRONG&gt;Change Manager&lt;/STRONG&gt; role&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Even admins will not be able to edit the field unless they meet one of the above conditions.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;EM&gt;"If you found my answer helpful, please&lt;STRONG&gt; like and mark it as an "accepted solution".&lt;/STRONG&gt; It helps others find the solution more easily and supports the community!"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank You&lt;BR /&gt;Juhi Poddar&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 06:19:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130416#M1840</guid>
      <dc:creator>Juhi Poddar</dc:creator>
      <dc:date>2024-12-18T06:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Want to write script for the below use case</title>
      <link>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130523#M1841</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/554909"&gt;@BoyaGaneshkumar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for marking my response as helpful.&lt;/P&gt;
&lt;P&gt;As per new community feature you can mark multiple responses as correct.&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct as well so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2024 08:47:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/want-to-write-script-for-the-below-use-case/m-p/3130523#M1841</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2024-12-18T08:47:23Z</dc:date>
    </item>
  </channel>
</rss>

