AppMachine Help Center

How can we help you?

Follow

Use data from your Excel or Web Service blocks in other blocks

When working with data driven blocks like Excel or Web Service you often want to use data from these blocks in other blocks. Lets say you have a data feed containing twitter profile names and you want to show the twitter timeline in your app based on a selection made by the user.

In this how-to we will explain how you can reuse data from your data block in other (child) blocks.

Note: We are using this attached demo file during this how-to.

Prerequisites

  • An app containing an Excel or Web Service block (you can also use the attached demo file to create an Excel block);

How To

In this article we will show you how to use data from the attached demo file in other blocks. In this specific case we will be using the twitter profile name to load the associated timeline in our twitter block.

  1. Go to http://design.appmachine.com and sign in.
  2. Open the app containing the Excel or Web Service block you want to use data from;
  3. Select the Excel or Web Service block;
    3.png
  4. First you need to determine the name of the field you would like to use; in this case the field containing the twitter account name. Once you have selected the Excel or Web Service block you see a list of all the available fields;
    4.png
  5. In this case the name of the field we need to use is called "Twitter";
  6. Make sure the Excel or Web Service block is selected and click the "Add block" button.
    6.png
  7. Select the Twitter block (or the block you would like to use);
  8. Click "Add block";
    8.png
  9. In the next screen you will be prompted to enter the name of the Twitter account you would like to show in your app. This is where the magic happens. We won't be adding a valid Twitter account name but we will reference the Twitter field from the Excel block;
  10. Enter a { in the text field next to the large "Connect" button.
  11. Once you entered the { character a menu will appear showing all the fields from the selected Excel block. The only thing you have to do is select the appropriate field, in our case Twitter;
    9.png
  12. Once you've selected the correct field the result will look like this:
    12.png
  13. Click "Next";
  14. Enter the name of this block, and click "Finish";
  15. The Twitter block will be placed underneath the Excel block, and will be shown as a detail screen for you Excel block;
    15.png

Some additional info

So, what is actually happening when you use {data:Twitter} as the value of the Twitter account name property? Well, when you place any type of block underneath an Excel or Web Service block you will always be working with one entry (record) of your data.
When entering the text {data:FieldName} (where FieldName should be replaced with the name of your field) you are actually referring to the value of that specific field in the selected entry (record).

So when opening a block in your app, AppMachine will automatically replace everything starting with "{data:" and ending with "}" with the value of the referenced field.

Adjusting the title of a block

You could also use this feature to adjust the name of your building block by simply referring to a field in the title of your block like this:
Caption_of_a_block.png

Relational data

Let's say you are working with relational data. In the attached demo file there is also a sheet available called Agenda. And each entry in the sheet Agenda has a related Speaker. If you want to access data from the Speaker object, how would you do this?

It is actually pretty easy. We've applied the same trick, and the apps looks like this right now:

App_structure.png

Now I want to do the same, showing the Twitter timeline of the speaker, so when I repeat the steps above, the result of step 11 will look like this:

Related_fields.png

In the screenshot above we are referring the field twitter in the speakers sheet. So using . will indicate a relationship where speakers is the name of the related object / sheet and twitter the name of the field in the related object.

Attachments

Was this article helpful?
3 out of 3 found this helpful
Have more questions? Submit a request

Comments

  • Avatar
    Arpana Karanjit

    Can we use data from Excel block in our JavaScript?

  • Avatar
    Matthijs Koopman

    Yes this is possible, the way you should do this is by adding an Excel building block to your app.

    Next add the JavaScript block as child of the Excel block, this will allow you to access the data from the Excel block.

    You can find information about the JavaScript SDK over here: https://support.appmachine.com/hc/en-us/articles/203990983-Module-core-js

    Or see the sample I've attached below:

    function onLoad(){
        document.title = App.Properties.__caption;  
        document.getElementById('blockName').innerText = App.Properties.__caption;
    
        getRecord();
        getAllRecords();
    };
    
    function getRecord(){
    
        //Get the select item in the excel block
        window.App.Core.getCurrentRecord(function(record){
    
            //Record does contain the JSON version of the selected item
            alert(JSON.stringify(record));
    
        });
    };
    
    function getAllRecords(){
    
        //Get all the records available in the excel building block
        window.App.Core.getRecords(function(records){
    
            //Loop through each record
            for(var i = 0; i < records.length; i++){
    
                //Get the current record
                var record = records[i];
                document.write(JSON.stringify(record));
            }
    
        });
    
    };
    
    
  • Avatar
    Richard
    Thanks this helped alot