Jump to content
  • 0

Passing a parameter through Caspio datapages using JS


VA123

Question

I have ticketing application, which is spread over many datapages (50+). Out of a userbase of 20, I have 5 users that don't need to see the full app, but only a 'limited' version. I think this could be achieved if I pass a parameter through the login authentication page, which would be received by any subsequent datapages the users visit(and then add conditional logic on each datapage to hide whatever needs to be hidden, if a specific parameter is received). My issue is the standard Caspio interface can only pass the login information (e.g. Email) as a parameter through the authentication page - e.g. [@testpar]?

<script>

document.addEventListener('BeforeFormSubmit', function (event) {
  var comparevar = document.getElementById("xip_Email").value;

  if (comparevar === 'user1email@test.com') {

  //pass   [@testpar] = 'limitedView'

}

});

</script>

Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Hi @VA123,

I think you can use Record-level Security.

Record level security is a feature of Authentication. It allows you to restrict access to records based on the current user’s profile data.

With record level security, you can allow access based on:

  • Records that were created by the current user
  • Records that were assigned to them personally

For more details about this, you can check this Article

I hope this helps.

Regards,

Ruel Jay

 

Link to post
Share on other sites
  • 0

Hi Ruel Jay,

Unfortunately record level security is not what I need to use here. I do not want to restrict the users access to data, I want to restrict the users access to specific datapage features. Hence the need to pass a parameter from the login screen. One example - if the user is Canadian, they have provinces for Zip Code, if the user is based in the US, we have Zip Codes and not provinces. Hence based on where the user is from different fields need to be shown/hidden in the data forms. 
If be great if you could take another look at my code and advise how I can pass a custom parameter.

CaspioData_2019-Feb-12_1534.zip

Edited by VA123
Attached a sample app with my code
Link to post
Share on other sites
  • 0

One way you could achieve this without JS is by creating one datapage for US/Zipcodes and one for Canada/Provinces. A parameter from your user table would be how they are redirected. I know you asked for JS to deal with it, however I'm not skilled enough yet to produce a script like that. Although it might be more work, I'm pretty confident this workflow will work for your needs.

Link to post
Share on other sites
  • 0

kpcollier, thank you for your feedback. Agreed, your solution would do the job you described, but unfortunately not my problem. 

1. I have 50+ datapages - I don't want to duplicate and redeploy all of them

2. The CA/US was just an example - there are a number of differences between the datapages that need to be implemented

Link to post
Share on other sites
  • 0
3 hours ago, VA123 said:

Hi Ruel Jay,

Unfortunately record level security is not what I need to use here. I do not want to restrict the users access to data, I want to restrict the users access to specific datapage features. Hence the need to pass a parameter from the login screen. One example - if the user is Canadian, they have provinces for Zip Code, if the user is based in the US, we have Zip Codes and not provinces. Hence based on where the user is from different fields need to be shown/hidden in the data forms. 
If be great if you could take another look at my code and advise how I can pass a custom parameter.

CaspioData_2019-Feb-12_1534.zip

Hi @VA123,

How do you intend to differentiate your users? I'm thinking of adding a Yes/No field in your user_Table to accomplish this, let's say that you only have two types of the user coming from US and Canada.

So in your user table, you can have a field name Canada(Yes/No DataType). If this is checked, your user is from Canada, if not we can assume that he/she is from the US.

Then in your DataPages, we will use this field in the 'Rules', and for this solution to work you will need to group the fields that you want to display to each user type under one 'Section'.

Then we will create a 'Rules' that if Canada is checked/'True' we will be hiding section 2 (where all the fields for your US only user type are grouped) or vice versa

I hope this makes sense if this is somewhat similar to what you are trying to achieve please tell me so that I can try to create a demo DataPage for this if you want.

Regards,

TsiBiRu

Link to post
Share on other sites
  • 0
23 hours ago, TsiBiRu said:

Hi @VA123,

How do you intend to differentiate your users? I'm thinking of adding a Yes/No field in your user_Table to accomplish this, let's say that you only have two types of the user coming from US and Canada.

So in your user table, you can have a field name Canada(Yes/No DataType). If this is checked, your user is from Canada, if not we can assume that he/she is from the US.

Then in your DataPages, we will use this field in the 'Rules', and for this solution to work you will need to group the fields that you want to display to each user type under one 'Section'.

Then we will create a 'Rules' that if Canada is checked/'True' we will be hiding section 2 (where all the fields for your US only user type are grouped) or vice versa

I hope this makes sense if this is somewhat similar to what you are trying to achieve please tell me so that I can try to create a demo DataPage for this if you want.

Regards,

TsiBiRu

How are you thinking of passing the Yes/No field from the user table to the 'Rules' section - 'Rules' cannot receive values from a different table - only parameters. Otherwise your solution is pretty close to what I had in mind. If you had a few minutes and do a Demo datapage, that could probably work as well. 

I am thinking of having a [Country] column in my user table. Let's say we have MX, US and CA as countries. The problem is that I cannot pass this [Country] column as a parameter through the Authentication datapage. And the 'Rules' section only has options for 'Condition', which are Field(from the underlying table of the datapage), Parameter and Value - therefore I don't know how to read the [Country] from the user table in the 'Rules' section, because [Country] is in another table(the user table), and is not passed. 
Hence, my ask for a JS solution on passing a custom parameter through the Authentication datapage, that can then be received/selected by the 'Rules' section. 

Thanks for looking into this.

Link to post
Share on other sites
  • 0

Hi @VA123,

I was able to create a sample app for this, I've exported it and attach to this response.

What I did is I added a field called Region in my user table (which is the source of my authentication), and I have 3 test user coming from 3 different regions (US, Mexico, California).

Then in my DataPage I've added a virtual field to get the region where the user that is logged in belongs to, I was able to do this by making the virtual field hidden and receiving the  region value from my authentication on load image.png.ca50d87965dc2c1ba52925ab3bd99923.png

 

Afterward, I've added a section to group the fields that I only want to display to each specific Region (In this example I only have 1 textbox for each region).

Then I've created a Rules for each region, to hide the section for each region if the user does not belong to that region. 

image.png.69047cc055337b862398afdda5df7845.png  

In the example below, if the user is not from the US, it will hide the section where the fields for this region is grouped.


image.png

Just play around with this, the default password for each user is 123.

I hope this helps you.

Regards,

TsiBiRu

Forum_Demo_For_VA123_1_0_2019-Feb-15_0020.zip

 

 

Link to post
Share on other sites
  • 0

Thank you very much. Your solution makes perfect sense and I was able to implement it. The demo you posted was helpful as well!

Just out of curiosity, is there a guide somewhere on how to pass parameters through JS through Caspio? Or what are some of the considerations I need to take into account if I ever had to pass parameters using JS through Caspio?

Link to post
Share on other sites
  • 0

Hi @VA123,

 

If my assumption is correct, is this the current implementation of the Login process of your app?

https://howto.caspio.com/tech-tips-and-articles/common-customizations/create-user-specific-redirect-after-login/

 

If Yes, might I suggest to to use a Submission Form DataPage instead of an HTML DataPage?

The idea is: behind your General/Master Authentication lies a Submission Form (with virtual fields) and Calculated Values (to define Values) and auto-submits using the script below (paste on footer).

<script>
  document.querySelector(`[action*="[@cbAppKey]"]`)
</script>

 

image.png.ccb0b71e7c69e2586e3e978c9da980cb.png

Reference: https://howto.caspio.com/tech-tips-and-articles/tech-parameters/add-a-search-interface-to-results-sets-page/

https://forums.caspio.com/topic/4314-js-auto-submit-a-datapage/ (An alternative to the script I provided)

 

For generating the destination URLs via Calculated Fields

https://howto.caspio.com/function-reference/

https://howto.caspio.com/datapages/datapage-components/calculated-values/

 

 

I hope this information helps.

 

Best Regards,

DefinitelyNot31337

Link to post
Share on other sites
  • 0
1 hour ago, VA123 said:

Thank you very much. Your solution makes perfect sense and I was able to implement it. The demo you posted was helpful as well!

Just out of curiosity, is there a guide somewhere on how to pass parameters through JS through Caspio? Or what are some of the considerations I need to take into account if I ever had to pass parameters using JS through Caspio?

Hi @VA123

I'm happy to know that I was able to help you out with this one :)

You can pass your parameter in Caspio as either an internal parameter (which you will set this on your DataPage to pass the value of your field on exit, here a screenshot: http://prntscr.com/mnedsm) this is the article about passing parameter

And since you want to pass this using JavaScript, I think the best option for you is to pass your parameters via query string, this is the link to Caspio's documentation about this.

<!-- Sample Code: Let's say that you have created the button below on a HTML block in your DataPage-->
<button onclick="myFunction()">Replace document</button>

<script>
  //this script will redirect the user on click of the button, and will pass the value of your field via query string
function myFunction() {
  location.replace("https://url_of_your_DataPage?testVariable=[@field:fieldName]")
}
</script>

 I hope this helps.

 

Regards,

TsiBiRu

Link to post
Share on other sites
  • 0
18 hours ago, TsiBiRu said:

Hi @VA123

I'm happy to know that I was able to help you out with this one :)

You can pass your parameter in Caspio as either an internal parameter (which you will set this on your DataPage to pass the value of your field on exit, here a screenshot: http://prntscr.com/mnedsm) this is the article about passing parameter

And since you want to pass this using JavaScript, I think the best option for you is to pass your parameters via query string, this is the link to Caspio's documentation about this.


<!-- Sample Code: Let's say that you have created the button below on a HTML block in your DataPage-->
<button onclick="myFunction()">Replace document</button>

<script>
  //this script will redirect the user on click of the button, and will pass the value of your field via query string
function myFunction() {
  location.replace("https://url_of_your_DataPage?testVariable=[@field:fieldName]")
}
</script>

 I hope this helps.

 

Regards,

TsiBiRu

Thank you for providing this additional feedback - it gives me a lot of material for experimentation to fill my free time.  

Link to post
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...