Jump to content

Preventing duplicates when creating new records using Set Variable


This topic is 2789 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

Hello. 

I have two tables: Person and Recruiting

Within Person, I have a field Person::Source (which indicates the recruiting event we first met the person)

Withing Recruiting, a record is created for each recruiting event. 

I have the Person::Source field set to run the following script each time I enter a new Person record, which then creates a new Recruiting record

Freeze Window

Set Variable [$Source; Value: Person::Source]

Go to Layout ["RecruitingList" (Recruiting)]

New Record/Request

Set Field [Recruiting::Recruiting Event; $Source]

Go to Layout [original layout]

The problem I am having is that we have several Person records with the same Person::Source value, and each time I run the script is creates duplicate records in Recruiting. Is there anything I can add to the existing script that will prevent the new record from being created if it the record already exists? 

 

 

 

Edited by Lee Smith
Removed the Red Text
Link to comment
Share on other sites

Sure, after the Go To Layout, do a search first and only create a new record when the Find does not find anything.

As an aside: you don't need to use a global variable ($$source) here, a local variable will do: http://www.soliantconsulting.com/blog/2014/02/all-variables-should-be-global-or-not

Link to comment
Share on other sites

I would start by defining the Recruiting Event field to validate as Unique.

Then make your script:

Freeze Window
Set Variable [$Source; Value: Person::Source]
Go to Layout ["RecruitingList" (Recruiting)]
Set Error Capture [ On ]
New Record/Request
Set Field [Recruiting::Recruiting Event; $Source]
Commit Records/Requests
If [ Get ( LastError ) = 504 ]
  Revert Record/Request [ No dialog ]
End If
Go to Layout [original layout]

 

  • Like 2
Link to comment
Share on other sites

This topic is 2789 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.