Jump to content

Javascript to process 1 of 2 Datapages based on table data


Recommended Posts

Hello,

I have a search and report datapage where I have added an HTML block in the results section which has an iFrame element inside of it. I am trying to accomplish this:

User processes a search, results are shown where some results will equal saved results from another table. So table (A) produces results that I want to cross-check to table (B). If there is a match based on an ID field in both tables (A+B), I want the iFrame element to show basic data (timestamp & user name). I was successful in doing this part...

Here is where I am having problems....

If table (B) does NOT match (right now shows "No record found."), I want the iFrame to show another datapage which is a form submit (this is the form that copies the data from table (A) to table (B).

I am actually able to get both of these parts working, but I cant get them to work together. So I can either get the results page to show a button that says "save" and then it saves that data from table (A) to table (B). But then it won't show the timestamp and user name after a page refresh. Or I can get the results page to show timestamps and user names even after a page refresh, but then I can't get the "Save" button/option to show. I need some sort of Javascript if/then option.

Thank you for ANY help with this!!!

Link to comment
Share on other sites

1 hour ago, MayMusic said:

If the second page is a tabular report page then you can enable Insert option in the report page

Thank you SO much for responding! I am desperately trying to solve this part of my app so I can move forward with my project.

 
Regarding your solution. I am looking for a solution that provides a more automatic result for the user. My app provides users with a searchable database (Table_A) where users search the database and are presented with results. Each user can save as many individual results as they want into another table (Table_B).
 
Table_B is full of copies of results from Table_A, differentiated by user_ID. So theoretically, you and I can both save item #5 to Table_B and when either of us search Table_B, we only see the one copy of the item based on System Authentication.
 
I have another table (Table_C) which is a table full of comments that are tied to each of the individual results from Table_B. But I don't want to get off track on that part right now.
 
What I am trying to achieve is this: I want users to conduct the initial search in Table_A (which is non-editable by anyone but Admin) and when results are presented, I want there to be some identification (automatically on load) in each line of the results, for each item; if that unique user has a copy of that item saved already to Table_B. Something like "Saved by: User_#5"
 
And for each item that is NOT already saved into Table_B for that unique user, in the place of the "Saved by: User_#5" option; I want there to be a button that says "Save Item". This button then makes a copy of that single item from Table_A, to Table_B. When it makes this copy it copies over the User_ID to that copy, so that record in Table_B is then unique to that user...even if there are already 500 other copies of that same record by 500 other users.
 
I hope that makes sense? =) The most important part is, both the "Save" button and the "Saved by" printout, are unique to each user. So at any time, each user can see either option for the same record.
 
Thanks again for ANY help you can provide!
Link to comment
Share on other sites

  • 4 weeks later...

In this case you can create a view to join these two tables based on Item_ID. Include all from TableA and only matching from TableB.

 

Create a report based on table A and add a calculated field to get the name of the user who has saved the record:

Calculated field 1:

SELECT TableB_UserID FROM _v_JoinedAandB WHERE TableA_ItemID = [@field:ItemID]

Another calculated field to see which ones are already saved using the code below
Calculated field 2:

SELECT
CASE
WHEN TableB_ItemID is not null THEN 'Saved'
ELSE 'Open'
END
FROM _v_JoinedAandB WHERE TableA_ItemID = [@field:ItemID]

"JoinedAandB" is the name of the view in the code above

Add a HTML Block and use this script:

<div id="id[@field:ItemID]"></div>
<script>

if ('[@calcfield:2]' == 'Open') 
document.getElementById('id[@field:ItemID]').innerHTML= '<a href="http://URL OF SUBMISSION PAGE TO TABLE B">Save This Item</a>'; 
else document.getElementById('id[@field:ItemID]').innerHTML = "Saved by [@calcfield:1]"; 
</script>

 

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
Reply to this topic...

×   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...