Calculated field option within tablefield

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Calculated field option within tablefield

Post by RonP » 2022-05-29 14:07

Hi,
What do I mis :x
I try to generate a URL, based on Zip code and House number (Based on that you should go to a Dropbox directory)
The given SQL-statement goes well, except that all the records in the table gets the SAME URL content.

Code: Select all

SELECT CONCAT("<a href=""https://www.dropbox.com/home/Energiecoach/DossierBewoners/",
              `Aanvragen`.`Postcode`,
              `Aanvragen`.`Huisnummer`,
              `Aanvragen`.`Toevoeging`,
              """",
              "  target=""_blank",
              " rel=""noreferrer noopener"">",
              `Aanvragen`.`Postcode`,
              `Aanvragen`.`Huisnummer`,
              `Aanvragen`.`Toevoeging`,
              "</a>"
) AS url from `aanvragen`
When I expand this with a where clause, then none of the NEWLY created records receive the wanted URL, and changed Zip code / House number doesn't result in a new URL.

Code: Select all

where `aanvragen`.`Id` = %ID%
Thanks in advance

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Calculated field option within tablefield

Post by pbottcher » 2022-05-29 20:42

Hi Ron,

did you check that you use Id as the primary key in your AppGini definition?

Otherwise you may try

Code: Select all

where %PKFIELD% = %ID%
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Calculated field option within tablefield

Post by RonP » 2022-05-30 10:00

Hi Pböttcher.
Thank you for pointing to a solution, however :)
I can’t get it done.
New records don't get the expected calculated result
Changed records don't get a changed calculated result
Ron

(I'm using V22R13 revision 1291)
Attachments
Calculated_field.JPG
Calculated_field.JPG (143.46 KiB) Viewed 1499 times

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Calculated field option within tablefield

Post by RonP » 2022-06-01 16:04

Subject can be closed :D !
There seemed to be a SQL-statement conflict, debugging and it works now as expected

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Calculated field option within tablefield

Post by RonP » 2022-06-06 14:08

Well.....

It turned out to be that the used concatination in the SQL-statemnet gives a problem.

The case:
I like to concatenate 3 fields and work to an url.
In fact it works well, however whenever the last field is empty (Toevoeging) the URL isn't created.
The field defenition in the database:

The defenition in AppGini: (Admin Area:View rebuild fields)

Code: Select all

Toevoeging	VARCHAR(40) NULL	VARCHAR(40)
The content of the calculated field is:

Code: Select all

SELECT CONCAT("<a href=""https://www.dropbox.com/home/Energiecoach/DossierBewoners/",
              UPPER(`aanvragen`.`Postcode`),
              UPPER(`aanvragen`.`Huisnummer`),
              UPPER(`aanvragen`.`Toevoeging`),
              """",
              "  target=""_blank",
              " rel=""noreferrer noopener"">",
              UPPER(`aanvragen`.`Postcode`),
              UPPER(`aanvragen`.`Huisnummer`),
              UPPER(`aanvragen`.`Toevoeging`),
              "</a>"
) AS url from `aanvragen`
where `aanvragen`.`Id` = %ID%
The Resultfield for calculated field is: `Dropbox-link` (Admin Area:View: rebuild fields)

Code: Select all

Link_Dropbox	VARCHAR(255) NULL	VARCHAR(255)
Generated HTML when filed `Toevoeging`is filled:

Code: Select all

<!-- Field: Link Dropbox -->
				<div class="form-group aanvragen-Link_Dropbox">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3">Link Dropbox <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#Link_Dropbox-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="Link_Dropbox-description"><div class="alert alert-info bspacer-xs">Wordt gegenereeerd uit: Postcode, Huisnummer, Toevoeging</div></span>
						<div class="form-control-static" id="Link_Dropbox"><a href="https://www.dropbox.com/home/Energiecoach/DossierBewoners/1852AM140D" target="_blank rel=">1852AM140D</a></div>
					</div>
				</div>
So whenever field `Toevoeging`has a vlue an URL has been created

<a href="https://www.dropbox.com/home/Energiecoa ... 1852AM140D" target="_blank rel=">1852AM140D</a>

Generated HTML when fieldd `Toevoeging` is not filled out:

Code: Select all

<!-- Field: Link Dropbox -->
				<div class="form-group aanvragen-Link_Dropbox">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3">Link Dropbox <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#Link_Dropbox-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="Link_Dropbox-description"><div class="alert alert-info bspacer-xs">Wordt gegenereeerd uit: Postcode, Huisnummer, Toevoeging</div></span>
						<div class="form-control-static" id="Link_Dropbox"></div>
					</div>
				</div>
So whenever field `Toevoeging` has NO value an URL has NOT been created

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Calculated field option within tablefield

Post by pbottcher » 2022-06-06 18:47

Hi again,

try

CONCAT_WS("","

instead of

CONCAT("
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
RonP
Veteran Member
Posts: 219
Joined: 2013-08-27 13:36
Location: Heiloo, The Netherlands
Contact:

Re: Calculated field option within tablefield

Post by RonP » 2022-06-07 18:07

That did the trick :D
Thank you.
Ron

Post Reply