Jump to content
Server Maintenance This Week. ×

Sreen Shots for Find or Create New script


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

Recommended Posts

Question from another forum

"Does anyone have any example of a button from one database that will go to the same record in another database with the same ID. But I need it to first search all the records in the second database so that if there are multiple records with that ID it will show them.. if not then create a new record and set the ID field to what the ID field is in the first database. I have tried 100 different ways and can't get it to work correctly.

Thanks,"

See attached screen shots

ScreenShot for Find or Add Script.zip

Link to comment
Share on other sites

Hi Robert,

You could set your button in your first database to copy the ID from the field then perform external script in DB 2 lets call it Find_Or_Create

The Find_Or_Create Script would go something like this

Enter Find Mode []

Paste [select, "YourIDField"]

Perform Find [Replace Found Set]

If ["Status( CurrentFoundCount) > 0"]

Go to Layout [LayoutDisplayingSearchResults]

Else

New Record/Request

Paste [select, "YourIDField"]

End If

This should work but I have not tested it so may need tweaking slightly.

The only problem I can forsee is when no records are found it will show the relevant message, you would have to click to continue for the new record to be created. You could proably get around this though by adding a step - if Status(CurrentError) = 401 then do something.

Hope this helps

Ed.

Link to comment
Share on other sites

I'd go with a relationship here from file A to file B....

Main Script.

If (IsValid::your relationship)

Go to Layout with Portal

Else

SetField(g_NewID, ID)

Perform External script

Refresh

External Script

SetField (g_ID, ???:Constant:g_NewID)

New Record

SetField (ID, g_ID)

Link to comment
Share on other sites

Robert,

Are you saying the quotes were from another user on another Forum and this was your answer ?

Sorry about that then. At least I'm not worried anymore...???

Hmm..

If that member was a man, I'm OK with this. If it was a girl, you're not a GentleMan grin.gif

What a Pain with Find mode this seems to me...

At least it works perfectly I assume

Link to comment
Share on other sites

I've attached a small example solution for this that basically uses the IsValid(ID | File2_ID::Constant) test. From there you branch to either displaying matching records, or creating a new related record. It's really easy to set up this kind of scripted process without having to perform any finds.

If you have any questions about the example files, email me smile.gif

Match_or_Create.zip

Link to comment
Share on other sites

Is this sample done with FM 6.0 ?

I can't get it to work on 5.5 as there are some steps missing in the script.

But Yes, from what you're describing, either IsValid or not IsEmpty would be easier.

As Robert already pointed though, he just was lazy.... wink.gif

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

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