Tap Forms app icon half
Tap Forms Forum text image
Blue gradient background

Exchange tips and ideas with the Tap Forms community

Search Results for 'script'

Viewing 15 results - 1 through 15 (of 2,875 total)
  • Author
    Search Results
  • #52610
    Mark Moran
    Participant

    I’ve written this javascript to go out and grab sold ebay items and store then in my database. I can’t seem to get it to work. ChatGPT says it because: “Tap Forms JavaScript scripting engine does not have direct HTTP request capability (like fetch or XMLHttpRequest). Scripts are sandboxed and cannot reach out to the web directly.”

    Is this true? Any suggestions on how to get this down if this is the case? I’d like to use the script on my Mac and iOS devices.

    // Define Field IDs from the current form
    const coinTypeFieldId = ‘fld-7b49d2da923f4e90a22c2c43d476504b’;
    const yearFieldId = ‘fld-2196446daf504b619016cf97e293fa00’;
    const mintmarkFieldId = ‘fld-81ea772bc0e24626977c0d2ddece998e’;

    // Defind Field IDs for the Coins on Ebay form
    const Ebay_coin_type_id = ‘fld-1dcc89f4289e482c93cbc940fbe7ca09’;
    const Ebay_mint_mark_id = ‘fld-1e874b9e81c94622837943a57654a563’;
    const Ebay_year_id = ‘fld-2c3a9b6921084f909c69ac90b42335ea’;
    const Ebay_price_id = ‘fld-20c6a1a5d6a74538acccd39458d8c61e’;
    const Ebay_photo_id = ‘fld-e86d4deab234444db94a4b06e731e919’;
    const Ebay_web_site_id = ‘fld-d77c51322b99468193c94ba823fca06b’;

    // Define the Forms
    const coinsWantedForm = document.getFormNamed(‘Coins Wanted’);
    const coinsOnEbayForm = document.getFormNamed(‘Coins on eBay’);

    // Get the current record
    //const currentRecord = form.getRecord();

    // Get the coin search details directly from the record
    const coinType = record.getFieldValue(coinTypeFieldId);
    const year = record.getFieldValue(yearFieldId);
    const mintmark = record.getFieldValue(mintmarkFieldId);

    // eBay API Setup
    const EBAY_AUTH_TOKEN = ‘API TOKEN REDACTED’;

    const query = ${coinType} ${year} ${mintmark};

    // eBay Search URL
    const url = https://api.ebay.com/buy/browse/v1/item_summary/search?q=Lincoln%20Penny%201909%20S&filter=sold_status:SOLD;

    console.log(Searching eBay for: ${query});

    // Async Fetch Wrapper for Tap Forms
    async function fetchEbayData() {
    try {
    const response = await fetch(url, {
    method: ‘GET’,
    headers: {
    ‘Authorization’: Bearer ${EBAY_AUTH_TOKEN},
    ‘Content-Type’: ‘application/json’
    }
    });

    if (!response.ok) {
    throw new Error(HTTP Error: ${response.status});
    }

    const data = await response.json();

    if (!data.itemSummaries || data.itemSummaries.length === 0) {
    console.log(‘No eBay items found.’);
    return;
    }

    // Create Coins Wanted Record
    const wantedRecord = coinsWantedForm.addNewRecord();
    wantedRecord.setFieldValue(coinTypeFieldId, coinType);
    wantedRecord.setFieldValue(yearFieldId, year);
    wantedRecord.setFieldValue(mintmarkFieldId, mintmark);

    // Prepare link field array
    const linkedEbayRecords = [];

    // Process each eBay item
    for (let item of data.itemSummaries) {
    const ebayRecord = coinsOnEbayForm.addNewRecord();
    ebayRecord.setFieldValue(Ebay_coin_type_id, coinType)
    ebayReocrd.setFieldValue(Ebay_year_id, year)
    ebayRecord.setFieldValue(Ebay_mint_mark_id, mintmark)
    ebayRecord.setFieldValue(Ebay_price_id, item.price.value);
    ebayRecord.setFieldValue(Ebay_web_site_id, item.itemWebUrl);

    // Save all available photos
    let allPhotos = [];

    // Add the main image
    if (item.image && item.image.imageUrl) {
    allPhotos.push(item.image.imageUrl);
    }

    // Add additional images if available
    if (item.additionalImages && item.additionalImages.length > 0) {
    item.additionalImages.forEach(img => {
    if (img.imageUrl) {
    allPhotos.push(img.imageUrl);
    }
    });
    }

    // Save all photos to the Photo field (must be a Photo field that accepts multiple items)
    ebayRecord.setFieldValue(Ebay_photo_id, allPhotos);

    // Save all photos (only saves the featured photo)
    // if (item.image && item.image.imageUrl) {
    // ebayRecord.setFieldValue(‘fld-ebay-photo-id’, [item.image.imageUrl]);
    // }

    linkedEbayRecords.push(ebayRecord);
    }

    // Link eBay records to Coins Wanted
    wantedRecord.setFieldValue(‘Coins on Ebay’, linkedEbayRecords);

    console.log(Found and linked ${linkedEbayRecords.length} eBay items.);

    } catch (error) {
    console.error(‘eBay API Error:’, error);
    }
    }

    // Start the async function
    fetchEbayData();

    #52597

    In reply to: Cascading Pick Lists

    Brendan
    Keymaster

    At the moment, no. I haven’t exposed the values relationship of a Pick List value to JavaScript yet.

    But I did just add the APIs to expose them to JavaScript.

    Will be in the next build (1.0.7) that I’m working on.

    #52593
    timzu
    Participant

    Does anyone know if there would be a way through scripting (or some other way) to change rating stars into another type of shape? Like if I wanted it to just be a rectangular block?

    #52587

    In reply to: Autofill advice

    Daniel Leu
    Participant

    1) change the double-quotes to single-quotes.
    2) since it’s a field script, you should not need the record.setFieldValue() since the return value is what is used.

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #52584

    In reply to: Autofill advice

    Mark Moran
    Participant

    Just came back here to say it’s not updating. It is setup as a field script (see attachment). According to the docs anytime I change the Coin Type it should run the script, no? It’s not, I have to manually click the “play arrow” on the script to get the field to update.

    • This reply was modified 5 days, 3 hours ago by Mark Moran.
    Attachments:
    You must be logged in to view attached files.
    #52582

    In reply to: Autofill advice

    Daniel Leu
    Participant

    Thank you for the coffee! I appreciate it!

    One more thing: My intention for the script was, that it’s used as a field script and not a form script. This way, whenever you set the coin type, the denomination field is automatically set.

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #52580

    In reply to: Autofill advice

    Daniel Leu
    Participant

    My script wasn’t intended to save the value to a field, but the return value would be the denomination. To save the field value, you need to use record.saveFieldValue() as you do, but you need to add document.saveAllChanges(); as well.

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #52574

    In reply to: Autofill advice

    Mark Moran
    Participant

    Ah, makes sense. Thanks. It works but it doesn’t update the field. I’ve tried updating a text field demonination or the script field itself but it remains blank. I added the bolded lines below and it still isn’t working:

    const coin_type_id = “fld-1231556e0f234de9b2d85f50225b8135”;
    const coin_type_demon = “fld-b7559ec0da8b4b42a9d270e1686e4746”;

    // get the denomination from the matching coin type record
    const denomination = matchingCoinType.getFieldValue(coin_types__denomination_id);

    record.setFieldValue(coin_type_demon, denomination);

    // return the denomination
    return denomination; // set return type as tex

    • This reply was modified 5 days, 6 hours ago by Mark Moran.
    • This reply was modified 5 days, 6 hours ago by Mark Moran.
    #52564

    In reply to: Autofill advice

    Mark Moran
    Participant

    Wondering if I can or should someone move this to the Scripting forum??

    I tried what you suggested. Both forms are in the same document and I’ve double checked the fld’s. But I get this error???

    Get Demonination: ReferenceError: Can’t find variable: getFieldValue, line:(null)

    =====

    // define fields in the main form
    const coin_type_id = “fld-1231556e0f234de9b2d85f50225b8135”;

    // define fields of coin types form
    const coin_types__type_id = “fld-415d31330587455cab106835b1d075fe”;
    const coin_types__denomination_id = “fld-528c65271e894ebda93268d20f2329ad”;

    // get the coin type from the main form
    const coinType = getFieldValue(coin_type_id);

    #52553

    In reply to: Autofill advice

    Daniel Leu
    Participant

    I would create a form for your coin types with two (or more fields), one is the type and the second one is the denomination. This way, you have an easy way to enter your data. A pick list would use that table as input which then is used for your dropdown.

    Then the denomination field can be set as the result of a field script. Following is an example. It should work but I haven’t verified it!

    You need to set the field ids and the form name according to your database.

    function getDenomination() {
        // define fields in the main form
        const coin_type_id = "fld-xxxxxx";
    
        // define fields of coin types form
        const coin_types__type_id = "fld-xxxxxx";
        const coin_types__denomination_id = "fld-xxxxxx";
    
        // get the coin type from the main form
        const coinType = getFieldValue(coin_type_id);
    
        // get the types from the coin types form
        const coinTypeForm = document.getFormNamed("Coin Types");
        const coinTypeRecs = coinTypeForm.fetchRecords();
    
        // get the matching coin type record
        const matchingCoinType = coinTypeRecs.find(coinTypeRec => coinTypeRec.getFieldValue(coin_types__type_id) === coinType);
    
        // get the denomination from the matching coin type record
        const denomination = matchingCoinType.getFieldValue(coin_types__denomination_id);
    
        // return the denomination
        return denomination; // set return type as text
    }
    
    getDenomination();
    • This reply was modified 6 days, 10 hours ago by Daniel Leu.

    Cheers, Daniel
    ---
    See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks

    #52550
    Mark Moran
    Participant

    Hi,

    I’m looking for some advice. I know just enough about scripting/programming to get myself in trouble.

    I’m setting up a coin database. There will be a dropdown field for coin types (e.g., Lincoln Penny, Jefferson Nickel, etc.) and a separate field for denomination (e.g., 1 cent, 5 cent, 1 dime).

    I’d like the denomination field to autofill based on the selected coin type. Some coin types will share the same denomination (e.g., both Lincoln Penny and Indian Head Penny = 1 cent).

    What’s the best way to accomplish this—using a script, a calculated field, or something else?

    Thanks!

    shire23
    Participant

    Hey Brendan,

    I’m really enjoying TF Pro. You have done an incredible job with all versions of TF. I’m proud to say I’m a long-time TF user. I guess it was probably around 2009ish I found TF on the App Store and fell in love with it. I was amazed at how I could have a fully functional and customizable database on my phone, especially right when the App Store was really just starting to get its footing. TF was way ahead of its time and still is. After a number of years I became a traitor and went to Android for a while. The whole time I was on Android I was chasing that TF experience in the Google Play store to no avail. When I came back to iPhone I snatched up TF5 and use it every day. Now I’m happy to upgrade to a Pro subscription and support an amazing app by an incredible developer.

    The new features have been great and I have only ran into one issue so far. I have a form in TF that I use to track product reviews. One of the fields in my form is a Note field titled “Review”. In TF5 I configured this field so that it has a default value of the review template I created (ss attached). I upgraded from TF5 and imported my .tfarc file into TF Pro. When I go into the field options for my Review field in TF Pro and tap into the “Default Value” option the app crashes immediately. Is this something you’ve heard of happening before? Thanks a ton!

    -Josh

    Attachments:
    You must be logged in to view attached files.
    #52492
    Tap forms Forum
    Participant

    Is there a way to read/write to sub-levels in Cascading Pick Lists in scripts?

    karen james
    Participant

    That last paragraph should read “this wouldn’t apply to anyone who chose to end their subscription. This would only apply should you not be able…”

    karen james
    Participant

    A question, Brendan. Please keep in mind that this is coming from a person that has absolutely no experience in development or dealing with the App Store or how it works. I’m just throwing this at the wall as it were.

    Is there a way you could switch things to non-subscription should you find yourself in a situation where continuing to work on TFP wouldn’t be possible, and it would cause the app to become non-functional for users? Or, is there someone that you could trust with the reins temporarily, if needed.

    This wouldn’t apply to anyone who chose to end their subscription. This wouldn’t apply only because applicable should you not be able to continue your efforts with the app that would interfere with its ability to function. Just something to put out there to ease users concerns?

    Again, no clue here. Just spaghetti at the wall!

Viewing 15 results - 1 through 15 (of 2,875 total)