Need to update linked field for multiple records

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Need to update linked field for multiple records

Viewing 1 reply thread
  • Author
    Posts
  • November 24, 2024 at 10:50 AM #51323

    Surya Paidimarry
    Participant

    Dear Tapforms,
    I have two forms, namely Project and Tasks. I have a linked field called Project Name that connects the Projects form to the child form, Tasks. I’ve created a script to automatically generate a set of tasks. However, I need to update these tasks with the Project Name. I tried using Advanced Find and Replace, but it doesn’t display the linked field, which I learned is a limitation. Manually updating each task is very time-consuming. Could you please suggest how I should proceed? I’ll paste my code for populating the tasks below. Any examples or corrections would be greatly appreciated. I’m not a professional coder, but I can research and accomplish my needs by following examples. Thank you all for your support. Happy TapFarming!

    function Ais_Pum_Default_Tasks() {

    var title_id = ‘fld-a34e5fd309dc4a9385d4b44736547f96’;
    var priority_id = ‘fld-cf942f13d8f14338966a81ccdd30ad81’;
    var category_id = ‘fld-fe9f869cf75a484ab4e3ca70f4c3dc43’;
    var environment_id = ‘fld-4a3951d0ef7b4e24a7affbf0afdbe6e3’;
    var project_name_id = ‘fld-e63dc1cd09cc4448b5d9e92005cb2dcf’;
    var status_id = ‘fld-77ad662cdb234741a5aff92434f600ac’;

    var ServerRequest = form.addNewRecord();
    var InsConfPUM = form.addNewRecord();
    var CFOTool = form.addNewRecord();
    var LoadCustomizationPum = form.addNewRecord();
    var GeneratePreCompares = form.addNewRecord();
    var LoadBugsGenerateCP = form.addNewRecord();
    var PUMDMU = form.addNewRecord();
    var OutageDEVL = form.addNewRecord();
    var PUMDEVL = form.addNewRecord();
    var CheckDevArchiveQuery = form.addNewRecord();
    var RetroDev = form.addNewRecord();
    var OutageTest = form.addNewRecord();
    var PUMTEST = form.addNewRecord();
    var CheckTestArchiveQuery = form.addNewRecord();
    var HandOffCollegeTesting = form.addNewRecord();
    var TestingSignOff = form.addNewRecord();
    var CMticketProd = form.addNewRecord();
    var PUMPROD = form.addNewRecord();

    ServerRequest.setFieldValues({[title_id] : “PUM Server Selection”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “N/A”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    InsConfPUM.setFieldValues({[title_id] : “Install and Configure PUM”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “N/A”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    CFOTool.setFieldValues({[title_id] : “Configure CFO Tool in PUM”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “N/A”, [project_name_id] : “PUMXXX”, [status_id] : “Differred”});

    LoadCustomizationPum.setFieldValues({[title_id] : “Load Customization in PUM”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “N/A”, [project_name_id] : “PUMXXX”, [status_id] : “Differred”});

    GeneratePreCompares.setFieldValues({[title_id] : “Generate Pre-compares in PUM”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “N/A”, [project_name_id] : “PUMXXX”, [status_id] : “Differred”});

    LoadBugsGenerateCP.setFieldValues({[title_id] : “Load Bugids and generate Change Package in PUM”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “N/A”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    PUMDMU.setFieldValues({[title_id] : “Apply PUM on DMU”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92DMU”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    OutageDEVL.setFieldValues({[title_id] : “Send outage Notice for DEVL”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92DEVL”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    PUMDEVL.setFieldValues({[title_id] : “Apply PUM on DEVL”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92DEVL”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    CheckDevArchiveQuery.setFieldValues({[title_id] : “Run Archive query in Devl”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92DEVL”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    RetroDev.setFieldValues({[title_id] : “Hand off Dev to Development team for Retrofits”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92DEVL”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    OutageTest.setFieldValues({[title_id] : “Send Outage Notice for test environment”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92TEST”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    PUMTEST.setFieldValues({[title_id] : “Aplly PUM on test environment”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92TEST”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    CheckTestArchiveQuery.setFieldValues({[title_id] : “Run Archive query created by Cindy”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92TEST”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    HandOffCollegeTesting.setFieldValues({[title_id] : “Releae environment for college Testing”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92TEST”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    TestingSignOff.setFieldValues({[title_id] : “Testing sign off”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92TEST”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    CMticketProd.setFieldValues({[title_id] : “Open Change Management Ticket for Production move”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92PROD”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    PUMPROD.setFieldValues({[title_id] : “Apply PUM on PROD”, [priority_id] : “High”, [category_id] : “PUM”, [environment_id] : “F92PROD”, [project_name_id] : “PUMXXX”, [status_id] : “NotStarted”});

    document.saveAllChanges();

    }

    Ais_Pum_Default_Tasks();

    December 18, 2024 at 6:51 AM #51397

    JScottA
    Participant

    The following is a response from the Tap Forms 5 Assistant (an unofficial custom GPT for Tap Forms). Remember that Brendan is the say on anything Tap Forms related. Also, confirm with the manual for Tap Forms:

    To update tasks with the Project Name automatically when creating them in Tap Forms, you can enhance your script to dynamically fetch and assign the project name from the parent record to the linked tasks.

    Solution:

    The current limitation with Advanced Find and Replace for linked fields can be bypassed by modifying the script to propagate the Project Name value programmatically. Here’s how you can refine your script:

    Adjusted Code Example

    Replace the hard-coded “PUMXXX” value with a dynamic retrieval mechanism from the parent project record. For instance:

    function Ais_Pum_Default_Tasks() {
        // Field IDs
        var title_id = 'fld-a34e5fd309dc4a9385d4b44736547f96';
        var priority_id = 'fld-cf942f13d8f14338966a81ccdd30ad81';
        var category_id = 'fld-fe9f869cf75a484ab4e3ca70f4c3dc43';
        var environment_id = 'fld-4a3951d0ef7b4e24a7affbf0afdbe6e3';
        var project_name_id = 'fld-e63dc1cd09cc4448b5d9e92005cb2dcf';
        var status_id = 'fld-77ad662cdb234741a5aff92434f600ac';
    
        // Get the current record (assumed to be the parent Project record)
        var parentRecord = document.getFormNamed('Project').getSelectedRecord();
        if (!parentRecord) {
            console.log("No project record is selected.");
            return;
        }
    
        // Retrieve the Project Name from the parent record
        var projectName = parentRecord.getFieldValue(project_name_id);
    
        // Check if Project Name exists
        if (!projectName) {
            console.log("Project Name is not set for the selected project.");
            return;
        }
    
        // Define tasks and their attributes
        var tasks = [
            { title: "PUM Server Selection", priority: "High", category: "PUM", environment: "N/A", status: "NotStarted" },
            { title: "Install and Configure PUM", priority: "High", category: "PUM", environment: "N/A", status: "NotStarted" },
            // Add other tasks here...
        ];
    
        // Create and populate each task record
        tasks.forEach(function (task) {
            var taskRecord = form.addNewRecord();
            taskRecord.setFieldValues({
                [title_id]: task.title,
                [priority_id]: task.priority,
                [category_id]: task.category,
                [environment_id]: task.environment,
                [project_name_id]: projectName, // Assigning dynamic Project Name
                [status_id]: task.status
            });
        });
    
        // Save changes
        document.saveAllChanges();
        console.log("Tasks generated and linked with project: " + projectName);
    }
    
    Ais_Pum_Default_Tasks();

    Explanation:
    1. Retrieve Parent Record: The script fetches the current project record using getSelectedRecord() from the Project form.
    2. Dynamic Assignment: The Project Name is read from the parentRecord and assigned to each new task in the child Tasks form.
    3. Save Changes: After updating the tasks, document.saveAllChanges() ensures that changes are persisted.

    Benefits:
    • Efficiency: Eliminates the need for manual updates or Advanced Find and Replace.
    • Dynamic Linking: Automatically associates tasks with the correct project name.

    Testing:
    • Make sure you have the appropriate permissions and field IDs set correctly.
    • Select a project record in the parent form before running the script to ensure proper linkage.

Viewing 1 reply thread

You must be logged in to reply to this topic.