Create composite primary key
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2016 10:15 AM
Hello Team,
Can we have composite primary key created for a table ?
Table : sys_group_has_role
Composite Primary Key : Group, Role
Reason why we are adding it to avoid duplicate group role entry for same group.
Thank you,
Eashwar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2016 08:32 PM
Eashwar, if you are using Fuji or a later release you may refer to Unique Index and Adding a Database Index
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2021 01:30 PM
Here is an example of a buisness rule with a table called KeyValueStore that has the columns of entitytype and entityreference that if both columns have values that exist in a record then the update or insert aborts:
- Create a business rule in Studio. Give it a Name and for Table select the table to apply the business rule to. Check Advanced.
- On the When to run tab select 'before' for when and check Insert and Update.
- On the Actions tab check Add message and in Message enter a message. In my example I entered "Entity Reference and Entity Value already exist in table."
- On Advanced in Script I created the following script:
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('x_kmhus_snxt_toolk_keyvaluestore');
gr.addQuery('entitytype', current.entitytype);
gr.addQuery('entityreference', current.entityreference);
gr.query();
while (gr.next()) {
if(gr.sys_id != current.sys_id){
current.setAbortAction(true);
}
}
})(current, previous);
Hope this example helps anyone trying to create a composite key on a SN table.