- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2015 03:09 PM
We have a custom table where I have written (what I thought was a simple) BR to prevent a record from being created if:
- for every field_01 + field_02 combination, there needs to be a unique field_03 value.
e.g. field_01 = appName, field_02 = environment and field_03 = profileName
There should always be only one profileName for every appName and environment combination.
The table has many other columns per record, but these are the key fields.
The issue I have, is my (before) BR (with both insert and update checked) works when I create new records. And when I update an existing record where I change profileName frome "Joe" to "Sally" (assuming Sally does not already exist). However, if I now go and change any other value of other fields on the record, it prevents the update because profileName already exists. The only work-a-round for now until I fix this logic is that when I want to change one of the other field values, I have to temporarily change profileName to something unique while I make the save and then again rename it back to the original profileName again.
So is there a way to do this in one BR or do I need two, one for insert and one for update?
var tla = current.u_tla;
var env = current.u_environment;
var profile = current.u_profile;
var hostGR = new GlideRecord('u_cdm_host_migration');
hostGR.addQuery('u_tla', tla);
hostGR.addQuery('u_environment', env);
hostGR.addQuery('u_profile', profile);
hostGR.query();
if (hostGR.next()) {
current.u_profile.setError('Profile Name: ' +profile+ ' already exists for this TLA and Environment');
current.setAbortAction(true);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2015 12:20 AM
Hi emyrold,
From your explanation what I usderstand is there should always be only one combination of 'u_tla' + 'u_environment' + 'u_profile'. While creating a new record the uniqueness must be checked. While updating an existing record, if this combination is touched then again check the uniqueness. But if the combination of these three fields is not touched then there is no need of checking the uniqueness and let them update the record.
Please use below modified code and let me if you need anything else. If you want any change in the combination you can simply change the conditions in '(tla.changes() || env.changes() || profile.changes())'.
var tla = current.u_tla;
var env = current.u_environment;
var profile = current.u_profile;
if(!current.isValidRecord() || (tla.changes() || env.changes() || profile.changes()))
{
var hostGR = new GlideRecord('u_cdm_host_migration');
hostGR.addQuery('u_tla', tla);
hostGR.addQuery('u_environment', env);
hostGR.addQuery('u_profile', profile);
hostGR.query();
if (hostGR.next())
{
current.u_profile.setError('Profile Name: ' +profile+ ' already exists for this TLA and Environment');
current.setAbortAction(true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2015 10:41 PM
Thanks Erik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2015 11:34 AM
Nicely done
