Using Current Record ID with Action Button

This sub-forum is for discussing all topics related to AppGini Helper JavaScript Library, provided by bizzworxx as a third-party AppGini plugin.
Post Reply
hgarbe
Veteran Member
Posts: 57
Joined: 2020-01-21 17:35

Using Current Record ID with Action Button

Post by hgarbe » 2020-09-06 02:48

Hi to all,
I stumbled over a potentially easy problem, but I could't figured it out on my own using the search function in the forum or the bizzworxx Javasript Helper Documentation. Shortest way to explain my question:

Let's assume I wan't to add an action button creating a new entry in another table with a predefined value in a lookup where the predefined value is the current records ID.

Code below as described here: https://appgini.bizzworxx.de/products/j ... n-buttons/

Code: Select all

var dv = new AppGiniDetailView();
var actionbuttons = dv.actionbuttons;
var group = actionbuttons.addGroup("Additional Links");
group.addLink("Link 1", "TABLENAME_view.php?addNew_x=1&filterer_LOOKUPFIELDNAME=#ID#");
I did try #ID# as when redicreting after creation of new record, after that the way its described here https://appgini.bizzworxx.de/appgini/ho ... able-view/ by using a function with window.location.href.
Neither did work. Is there anything like AppGini.currentTableName() to get this done or any other simple way? Or do I have to use php?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Using Current Record ID with Action Button

Post by jsetzer » 2020-09-06 03:44

tl;dr

Code: Select all

var dv = new AppGiniDetailView();
var id = dv.getSelectedId();
var tn = dv.getTableName();
---

Good morning,
  • get primary key of current record in detail view
    • by using pure jQuery

      Code: Select all

      var id = $j('input[name="SelectedID"]').val();
      
    • using AppGini Helper Javascript Library

      Code: Select all

      var dv = new AppGiniDetailView();
      var id = dv.getSelectedId();
      
      or, if the field is visible in detail view,

      Code: Select all

      var dv = new AppGiniDetailView();
      var id = dv.getField("YOUR_PK_COLUMNNAME").getValue();
      
      Note that this will return undefined if that field does not exists for example if this has been configured as "[X] hide in detail view"
  • get name of current table in detail view
    1. using AppGini

      Code: Select all

      var tn = AppGini.currentTableName();
      
    2. using AppGini Helper Javascript Library

      Code: Select all

      var dv = new AppGiniDetailView();
      var tn = dv.getTableName();
      
    --
    [...] I did try #ID# the way its described here https://appgini.bizzworxx.de/appgini/ho ... able-view/ [...]
    In table view there is not one primary key but each row has an individual primary key. Therefore we need a placeholder which will be replaced by each row's primary key.
    The placeholder in table view is not #ID# but %ID%. This placeholder will not help you in detail view, as there should be exactly one primary key.
    --

    By the way:
    Since version 2020/06/25 there are two small helper functions for building url's:

    Code: Select all

    var url = AppGiniUrl.get("tablename"); 
    // tablename_view.php
    

    Code: Select all

    var url = AppGiniUrl.get("tablename", 123); 
    // tablename_view.php?SelectedID=123
    
    So, since 2020/06/24 you can build your add-new url like this:

    Code: Select all

    const SUBTABLENAME = "childtable_name";
    const LOOKUPFIELDNAME = "foreign_key_column_name";
    
    var id = dv.getSelectedId();
    let url = AppGiniUrl.get(SUBTABLENAME) + "?addNew_x=1&filterer_" + LOOKUPFIELDNAME + "=" + id;
    
    Now that I am reading the code above, I am considering whether I should add further functions in one of the next versions that will make it easier for you to concat such URLs.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

hgarbe
Veteran Member
Posts: 57
Joined: 2020-01-21 17:35

Re: Using Current Record ID with Action Button

Post by hgarbe » 2020-09-06 15:39

Thanks for that detailed explanation. Decided to use Appgini Helper way as I just need to add the Current Record ID as Parameter.
I'm going to check out the jQuery way later as it might be useful when I want to use other Values as the ID for a Action Button with Function call instead of a simple URL.
Could definitely be handy to have further functions to concat URLs in an easy way. If I come across more thought through usecases I gonna add them to this post. Also maybe you want to consider to mention dv.getSelectedId() in your Documentation for Action Buttons?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Using Current Record ID with Action Button

Post by jsetzer » 2020-09-06 17:03

Thanks for the hint.

I've created a blog post here (https://appgini.bizzworxx.de/appgini-he ... n-buttons/) and, as you have suggested, linked it in documentation for Action Buttons (https://appgini.bizzworxx.de/products/j ... n-buttons/)
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply