<?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 Re: How to set a combination of 2 fields unique? in ServiceNow AI Platform forum</title>
    <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197876#M154265</link>
    <description>&lt;P&gt;you can create field values based on a calculated value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the Dictionary Entry for the attribute, you can make it a Calculated Value to combine 2 fields or something similar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2020 13:15:29 GMT</pubDate>
    <dc:creator>bdubz7</dc:creator>
    <dc:date>2020-10-13T13:15:29Z</dc:date>
    <item>
      <title>How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197874#M154263</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;I have a table for Web Accounts. The entries should be unique based on the URL and Account ID entered. How&amp;nbsp;to set a combination of 2 fields to be unique.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 11:12:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197874#M154263</guid>
      <dc:creator>JLeong</dc:creator>
      <dc:date>2020-10-13T11:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197875#M154264</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You cannot have the table level configurations to create Unique field as combination of two fields. However, you can have a Before insert/update business rule on your table to validate your new entry.&lt;/P&gt;
&lt;P&gt;In the script section you can glide to current table and check if the record already exits with current records value i.e URL and Account ID. If record exist abort the operation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The sample code&amp;nbsp;would&amp;nbsp;be like:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var web_acc = new GlideRecord("web_account_table");
web_acc.addQuery('u_url',current.u_url);
web_acc.addQuery('u_account_id',current.u_account_id);
web_acc.query();
if(web_acc.next())
{
current.setAbortAction(true);
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Anil Lande&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 13:10:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197875#M154264</guid>
      <dc:creator>Anil Lande</dc:creator>
      <dc:date>2020-10-13T13:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197876#M154265</link>
      <description>&lt;P&gt;you can create field values based on a calculated value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the Dictionary Entry for the attribute, you can make it a Calculated Value to combine 2 fields or something similar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 13:15:29 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197876#M154265</guid>
      <dc:creator>bdubz7</dc:creator>
      <dc:date>2020-10-13T13:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197877#M154266</link>
      <description>&lt;P&gt;Thanks Anil!!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 14:35:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197877#M154266</guid>
      <dc:creator>JLeong</dc:creator>
      <dc:date>2020-10-13T14:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197878#M154267</link>
      <description>&lt;P&gt;Thanks bdubz7! I could try this too!&lt;/P&gt;
&lt;DIV class="hoverCardContainer lb-width ng-isolate-scope"&gt;
&lt;DIV class="popover ng-isolate-scope fade in bottom bottom-left ng-animate in-remove" title="" data-ng-animate="2"&gt;
&lt;DIV class="arrow"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 13 Oct 2020 14:36:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197878#M154267</guid>
      <dc:creator>JLeong</dc:creator>
      <dc:date>2020-10-13T14:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197879#M154268</link>
      <description>&lt;P&gt;No need for a calculated field or Business Rule - a unique index will do the trick.&amp;nbsp; See this article - &lt;A href="https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/table-administration/task/t_CreateCustomIndex.html"&gt;Create a table index&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 14:55:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197879#M154268</guid>
      <dc:creator>Jim Coyne</dc:creator>
      <dc:date>2020-10-13T14:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197880#M154269</link>
      <description>&lt;P&gt;Thanks so much Jim! Looks like this is the correct solution but I will consult first with my team.&lt;/P&gt;
&lt;P&gt;Appreciate your assistance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 16:28:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197880#M154269</guid>
      <dc:creator>JLeong</dc:creator>
      <dc:date>2020-10-13T16:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197881#M154270</link>
      <description>&lt;P&gt;I would combine the approaches from Anil and Jim.&lt;/P&gt;
&lt;P&gt;While Anil checks on the server-side whether there is a duplicate, Jim's approach checks a the database level. I think they both have a valid point.&lt;/P&gt;
&lt;P&gt;An index prevents that even other applications in the feature will violate the uniqueness constraint. However, with the server-side Business Rule can add a more comprehensible error message to the screen.&lt;/P&gt;
&lt;P&gt;In addition I would like to amend Anil's script. It fires an error if an existing record should be edited. Here is my approach:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {
	var gr= new GlideRecord("your_table_name");
	gr.addQuery('field1', current.field1);
	gr.addQuery('field2', current.field2);
	gr.query();
	if (program.next() &amp;amp;&amp;amp; gr.sys_id != current.sys_id) {
		gs.addErrorMessage("The combination of field1 and field2 is already used for another record.");
		current.setAbortAction(true);
	}
})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please notice in the condition the part where I check if the alleged duplicate record is different from the current record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 12:33:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/1197881#M154270</guid>
      <dc:creator>Hendrik6</dc:creator>
      <dc:date>2022-09-06T12:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to set a combination of 2 fields unique?</title>
      <link>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/3171829#M201801</link>
      <description>&lt;P&gt;This may be an ancient post but the above answer is not true, or is no longer true.&amp;nbsp;You can create a unique index based on multiple fields. If the current data violates the index you want to create you will have to either delete the offending record or delete all records. So this is best done when creating the table.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Go to table list or form&lt;/LI&gt;&lt;LI&gt;Right click header and choose &lt;STRONG&gt;Configure&lt;/STRONG&gt; &amp;gt; &lt;STRONG&gt;Table&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;scroll down to &lt;STRONG&gt;Database Indexes&lt;/STRONG&gt; related list&lt;/LI&gt;&lt;LI&gt;If there is an existing index on one of the fields you want to use you can optionally click it and drop the index. However when you create the new index the system will amend that index.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Click &lt;STRONG&gt;New&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Move the fields you want to the &lt;STRONG&gt;selected&lt;/STRONG&gt; box&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Check &lt;STRONG&gt;Unique Index&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Click &lt;STRONG&gt;Create Index&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TonyV_1-1738943578643.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/417934iD4D93F0828EC9F18/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TonyV_1-1738943578643.png" alt="TonyV_1-1738943578643.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 15:55:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/servicenow-ai-platform-forum/how-to-set-a-combination-of-2-fields-unique/m-p/3171829#M201801</guid>
      <dc:creator>Tony V</dc:creator>
      <dc:date>2025-02-07T15:55:14Z</dc:date>
    </item>
  </channel>
</rss>

