Jump to content

how to insert a value on a report page if box is checked


Recommended Posts

My app has two user bases, teachers and docents. Teachers schedule art lessons and docents sign up to teach the lessons. All docents and teachers have unique IDs and must log-in to the app. Docents can search the scheduled lessons and select a lesson to teach. Each lesson has 2 docents slots for lead and assistant.

There are 2 fields for each slot - Lead_Docent and a virtual checkbox (check to lead); Assist_Docent and virtual checkbox (check to assist). If there is a value in Lead_Docent or Assist_Docent, I have a rule to disable the checkbox and make the docent field display only so the user can't delete/overwrite another docent.

I need to assign the field Lead_Docent or Assist_Docent with the user's ID if the box is checked. This is what I've tried but it doesn't work. Help!

Virtual1  is set to receive onload  the value of the docent's ID through the authentication fields.

Virtual 3 and Virtual 4  are checkboxes, value if checked is Y

Lead_Docent and Assist_Docent are text fields

 

 

 

assign docent.rtf

Link to comment
Share on other sites

Hello @lamarh,

Since you are using 'EditRecordField_name', I understand that this is the Details or Single Record Update DataPage.

The code looks fine except for the quotes in the attached file. For example:

uw7XYdT.png

This code works on my side:

<script>
document.addEventListener('BeforeFormSubmit', function(event) {

const docentID = document.getElementById('cbParamVirtual1').value;
const leadbox = document.getElementById('cbParamVirtual3').checked;
const assistbox = document.getElementById('cbParamVirtual4').checked;

	if (leadbox) {
		document.getElementById('EditRecordLead_Docent').value = docentID;
		alert("you are signed up to lead");
       }
     
	else if (assistbox) {
		document.getElementById('EditRecordAssist_Docent').value = docentID;
		alert("you are signed up to assist");
       }
});
</script>

Did you check errors in console?

Link to comment
Share on other sites

I didn't know about checking for errors in console (newbie to javascript!) Thanks for catching the quotes typo! And yes, this is a details page.

It's still not working though. I copied and pasted your script and checked for errors.  At the line  

		document.getElementById('EditRecordLead_Docent').value = docentID

I get the error Uncaught type error: cannot set property 'value' of null

If I comment out that line and change the alert to 

alert(DocentID + ' is signed up to lead');

the alert works, with the correct DocentID, so DocentID isn't null

The javascript is in the footer and doesn't run until the user submits. I've triple checked for typos in the field name. Any clues?

 

1354904915_ScreenShot2021-08-16at11_27_56AM.thumb.png.51afef26844e94a82550e8a6aefae66f.png

Edited by lamarh
added text
Link to comment
Share on other sites

35 minutes ago, lamarh said:

I didn't know about checking for errors in console (newbie to javascript!) Thanks for catching the quotes typo! And yes, this is a details page.

It's still not working though. I copied and pasted your script and checked for errors.  At the line  

		document.getElementById('EditRecordLead_Docent').value = docentID

I get the error Uncaught type error: cannot set property 'value' of null

If I comment out that line and change the alert to 

alert(DocentID + ' is signed up to lead');

the alert works, with the correct DocentID, so DocentID isn't null

The javascript is in the footer and doesn't run until the user submits. I've triple checked for typos in the field name. Any clues?

 

1354904915_ScreenShot2021-08-16at11_27_56AM.thumb.png.51afef26844e94a82550e8a6aefae66f.png

It's the 

document.getElementById('EditRecordLead_Docent')

that's non-existent, are you sure this is Update Form or Submission Form? If this is a Submission Form. use InsertRecord instead of EditRecord

Link to comment
Share on other sites

This is definitely an update form. The art docent searches the table for lessons that have been scheduled and selects one to teach. By checking the box, the  Lead_Docent field should update to the user's ID, which is loaded into virtual1 as an authentication field.

Once this is working, I add a rule to hide the checkbox when Lead_Docent is already taken by another docent so it can't be overwritten.

Link to comment
Share on other sites

Problem solved and got rid of the javascript completely. I added a virtual field (Lead_on_load) that loads the value of Lead_Docent when the page loads. The Lead_Docent field is now a calculated field that either loads the user's ID or Lead_on_load depending on the status of the check box. When there is already a value in lead_docent, there is a rule to hide the checkbox so it's value is zero and Lead_Docent is "reset" to Lead_on_load. I hope that makes sense! I couldn't figure out why the Lead_Docent field was throwing the error. Love that I got rid of the javascript!

Link to comment
Share on other sites

  • 8 months later...

Thanks to lamarh  for commenting how they did this without Javascript. I couldn't get the Javascript to work and instead tried to do it all in CASPIO.

Here is some code that might help. Using a single hidden calculated field, it stamps the author if another field has a certain value. In this case, I wanted this field to only be author stamped once, and never update if other fields are updated.

 

image.png.cdee1dd3f4dacbb7fc269a26f9ce62bc.png

 

Another example that updates an author field only if a certain field value is changed using a combination of a Triggered Action and a Calculated Field:

 

image.png.50842b42cc52793907e44dc8b5c8f1d9.png

 

 

image.png.c32974cc62f738591d36f0ac1a9e9265.png

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