How to add Text to multiple records?

Viewing 6 reply threads
  • Author
    Posts
  • October 10, 2024 at 7:18 AM #51196

    Stephan Hartmann
    Participant

    Hi,

    is there a way to add text to a text field of multiple records? In My example I am sending out mailings and want to note that in those records which will get the mailing.

    The field is set up as a text field and has the selection thing, where I can choose from the list.  The first two mailings I just filld the field by dragging the yellow dot in a spreadsheet-style.

    Ticking off over one thousand records individually is quite time consuming.

    I thought I could select those records and then select from the list to add it. But that’s not possible.

    My attempt to do a script failed miserably, my brain seems to work the other way around.

    Any Ideas how this could be done? Or has anyone already done a script fot this kind of operation?

    Thanks

    Stephan

     

     

    Attachments:
    You must be logged in to view attached files.
    October 10, 2024 at 9:09 AM #51198

    Daniel Leu
    Participant

    Do you have some type of criteria to select these records? Can you create a saved search for them? Or is it for all records?

    Do add them to the list, I think the only way is using a script. Here’s an example of what I’m using:

    var prompterVar;
    
    function callbackSetTag() {
       const name_id = 'fld-xxx';
       const tags_id = 'fld-xxx';
       // get records from a saved search
       let recs = form.getSearchNamed('Selected').getRecords();
       // // use all records
       // let myRecords = form.getRecords();
       console.log('Found ' + recs.length + ' records');
       for (rec of recs){
          console.log("Processing " + rec.getFieldValue(name_id))
          var tags = new Array();
          // load initial values
          var tag = rec.getFieldValue(tags_id);
          // create an array of tags
          if (tag) {
             tags = tag.split(",");
          }
          // add new tag
          if (prompterVar){
             tags.push(prompterVar);
          }
          // save new tags
          rec.setFieldValue(tags_id, tags.toString());
          console.log("Setting tags: " + tags.toString());
       }
       document.saveAllChanges();
    };
    function setTag(){
       let prompter = Prompter.new();
       prompter.addParameter('Tag', 'prompterVar', 'text')
       .show('Add Tag to current record', callbackSetTag);
    }
    setTag();
    You will need to update the name_id and tag_id constants. name_id is used in the console log to provide some infos on which record the routine is running. tag_id is the field where you collect your tags. In your case, that would be the Mailings field.
    Next, you have to decide if this works on a saved search or on all records. My saved search is called Selected. Either you update this, or comment this line and uncomment the next block to perform the tagging on all fields.
    When you run the script, you get a prompter where you enter the new tag. Note, the tag may not contain commas!
    Hoffentlich hilft das. Viel Spass und Erfolg!
    October 11, 2024 at 2:09 AM #51199

    Stephan Hartmann
    Participant

    Thaks a alot! This acutally works. Danke!

    But something unexpected happened. I didn’t expect that it acutally adds the tags when clicking the play-button in the “Edit script” window, so now I have “Test” in every of those records. :/ I thougt it would check the script for errors but not actually perform it live. Any idea how to remove them again?

    I should set up a test database for testing.

    Questions:

    1. New tags are added without a space, which means the result is like: Tag1,Tag2,Tag3. How can I add a space in the script? For readability reasons I want to display it like this: Tag1, Tag2, Tag3  (I know that I will forget to add a space manually when entering new tags.)

    2. It performs the changes on the hardcoded saved search “Selcted”. Is it possible to “get” the currently displayed saved search? Or to enter/select, on which saved search it should be performed? (Not citical but it would streamline the workflow.)

    -Stephan

    Attachments:
    You must be logged in to view attached files.
    October 11, 2024 at 6:14 AM #51201

    JScottA
    Participant

    Perhaps this will help?

     

    Here’s how you can address the issues presented:

    1. Adding Spaces Between Tags

    To add a space between tags when concatenating them in a script, you can modify your script to concatenate tags with a comma and a space (“, “). You can do this by updating the part of your script where the tags are combined. For example, if you are using the CONCAT function, you can write:

    var tags = tag1 + “, ” + tag2 + “, ” + tag3;

    This will format your tags with a space after the commas, displaying them as Tag1, Tag2, Tag3.

    Alternatively, you can loop through a collection of tags and concatenate them dynamically with spaces like this:

    var tags = tagsArray.join(“, “);

    This will join all elements of the array tagsArray with “, ” between them.

    2. Performing Actions on the Currently Displayed Saved Search

    Unfortunately, there is no direct way to get the currently selected saved search in Tap Forms using a script. However, you can manually specify which saved search to run the script on by defining it in your script. For example, you can use:

    var selectedSearch = “My Saved Search”;

    If you wish to make your script more flexible and allow the user to input or choose the search when running the script, you would need to set that up manually, as Tap Forms doesn’t currently offer a script-based selection of saved searches dynamically.

    To streamline the workflow, I recommend testing your script on a sample or test database, as you mentioned, to avoid unintentional changes.

    For more details, refer to page 53 for information on scripting and handling such cases within Tap Forms .

    Let me know if you need further clarification!

    You can check out the Tap Forms Scripting 101 guide here.

    Try the Tap Forms 5 Assistant GPT here: https://chatgpt.com/g/g-aGOEAlajR-tap-forms-5-assistant

    October 11, 2024 at 8:42 AM #51202

    Daniel Leu
    Participant

    Hi Stephan,

    Yes, it’s always a good idea to make a copy of a document to try new things.

    I have updated and enhanced the script to work on the current search. Although ChatGPT claims that’s not possible, but it is :).

    Initially I didn’t use ‘, ‘ as a separator because I wasn’t certain that your input data is consistently using it. It now uses a comma when parsing the input, then removes all leading and trailing spaces, and finally uses ‘, ‘ when creating the output string. This makes it easier to read.

    Using a selector, you now define the operation of the script, either ‘add tag’ or ‘remove tag’.

    The script is getting a bit too long for the forum here. You can find it on my blog at https://lab.danielleu.com/blog/working-with-tags/.

    • This reply was modified 6 days, 17 hours ago by Daniel Leu.
    October 16, 2024 at 2:55 AM #51207

    Stephan Hartmann
    Participant

    Thanks Daniel. Just one word: Fantastic. I’ve first tested it in the sample database and then used it in my production database and everything worked flawless. All 1521 records have been updated by removing the “Test” tag and then adding the tag for my current mailing. It just took a few seconds without getting distracted. This really helps to create specific searches and keep track of who got which mailing.

    October 16, 2024 at 8:19 AM #51208

    Daniel Leu
    Participant

    Hi Stephan, great that it works for you! Thank you for letting me know!

Viewing 6 reply threads

You must be logged in to reply to this topic.