- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2019 08:51 AM
Hello Experts,
I have a before BR that generates a GUID on a field on Insert.
current.u_guid = gs.generateGUID();
What I need for to happen is that I want to check if every new entry's 'u_record_id' already exists in the table, If it does then copy 'u_guid' from the existing record to new record's 'u_guid' field, and if it doesn't, then generate a new one.
How can I achieve this?
Thanks in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2019 11:01 AM
You need an onBefore Insert Business Rule for this.
And in the script you need to write
var t = new GlideRecord('<Your table Name>');
t.addQuery('u_record_id',current.u_record_id);
t.query();
if (t.next())
{
current.u_guid = t.u_guid;
}
else
{
current.u_guid = gs.generateGUID();
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2019 09:09 AM
I am not quite sure what you ask is. If you want to know the sys_id of record before insert. Try using newRecord() method to find out sys_id of new record before actually committing to DB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2019 09:16 AM
Hi Yogi,
I'm not talking about checking for new sys_id, I'm wanting to check if NEW entry's u_record_id field has the same value in existing records, and if so, then copy the existing Record ID's u_guid to new entry's u_guid, otherwise generate a new u_guid.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2019 11:01 AM
You need an onBefore Insert Business Rule for this.
And in the script you need to write
var t = new GlideRecord('<Your table Name>');
t.addQuery('u_record_id',current.u_record_id);
t.query();
if (t.next())
{
current.u_guid = t.u_guid;
}
else
{
current.u_guid = gs.generateGUID();
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2019 11:41 AM
Hi Sanjiv, thanks for your reply.
I tried this out but whether or not there is a match, it's not setting the u_guid at all.