Jump to content
  • 0

Create a Record if Record ID does not Exist


TomWms

Question

I am on the Explore plan so I do not have use of Triggers. However my request should still be simple for such a system as Caspio. I what to know how I can "Create a Record if Record ID does not Exist" .

I have a Parent database where each record is only able to have ONE child in the Children database. I want to send the parent record_id to the child database and if it exists, then my submission form will allow further editing.  However, if the child record is NOT FOUND, then ADD IT and place the parents_id in the appropriate field in the Child DB.  I'm hoping to use only one DataPage to do this if possible. I can write some SQL but I can't figure out where you place this in Caspio.  Please Help!

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I'm not 100% sure on your use case. This sounds like you might be trying to bulk edit on a frequent basis, but without knowing that I've given a suggestion for a single record level.

When I've needed to do this, I've generally pushed my user to start the workflow from a view with the parent and passed the parameter into my new page, but if this isn't an option, in the child form you'll need some calculation as follows:

If you have a unique userid in authentication and parent table then the calc is simple:

ISNULL(SELECT parentid FROM yourtable WHERE userid='[@authfield:userid]' ),0)

 

If by table level, then you'll need to create a view with the two tables together, edit child table, then create the submission form from the details page. You could play with filters to find all the records missing child record, but I'm not sure that you'd be able to add with the matching parent id. You'd need to experiment with that

 

Link to comment
Share on other sites

  • 0

Hi @TomWms,

I suggest using the Rules, Virtual field, HTML Block and CSS:

1. The use of a virtual field is to check if the value is existing on the table, you can use SQL and Case statement:

CASE WHEN [@field:ID] = (SELECT (ID) FROM TABLE WHERE ID=TARGET.[@field:ID]) THEN 'VALUE IS ALREADY ON THE TABLE'
ELSE ' ' END

2. Add a rule where it will hide the HTML BLOCK
3. Add the code for the submit button
4. Add CSS code on the header of the DataPage

For reference: https://howto.caspio.com/tech-tips-and-articles/display-the-submit-or-search-button-inline/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...