Register associated records in the offline cache

  • Release version: Australia
  • Updated June 9, 2026
  • 1 minute to read
  • Configure a write-back action step by adding an execution script that registers newly created instance records for synchronization. Local and server-side records are then reconciled when connectivity is restored, preventing duplicate records.

    Before you begin

    Role required: mobile_admin, admin

    About this task

    When a record is created offline, it is assigned a temporary ID that needs to be matched with the permanent ID created on the server once connectivity is restored. You add the addRecordForSync() method to your write-back action step so that the offline and server records are automatically linked during synchronization, preventing duplicate records.

    Procedure

    1. Navigate to All > System Mobile > Mobile App Builder.
      The Mobile App Builder opens in a new browser tab and displays the application scope selection screen.
    2. Search for the application scope you are working in and then select the name of the application scope.
      The Mobile App Builder categories home screen displays.
    3. Select All mobile records from the menu.
    4. From the Record type field, select Action item [sys_sg_write_back_action_item], and then select the action item you created.
    5. In the Type field, select Script.
    6. In the Execution Script field, add the execution script, actionResult.addRecordForSync([tableName], [sysId]);
      For example, in the following script the write-back action creates a new time worked entry on the task_time_worked table. It retrieves the time worked value from the form input, creates a new record linked to the relevant task using its sys_id, and inserts it into the instance. The addRecordForSync() method is then called to associate the newly created instance record with the corresponding local record on the device, ensuring they are reconciled during the offline synchronization.
      (function WriteBackAction(parm_input,parm_variable,actionResult) { 
      
      var timeWorked = parm_input[“time_worked”]; 
      
      var gr = new GlideRecord("task_time_worked"); 
      gr.initialize(); 
      gr.task = parm_variable.task_sys_id; 
      gr.time_worked = timeWorked; 
      var newId = gr.insert(); 
      actionResult.addRecordForSync("task_time_worked", newId); 
      
      })(parm_input,parm_variable,actionResult); 
      Where:
      • task_time_worked is the tableName that contains the record created on the instance.
      • newIdis the sysIdof the record created on the instance.
      • actionResult is the object on which the addRecordForSync()method is called.
    7. Select Save.

    Result

    When the device reconnects and synchronization occurs:
    • The server creates the record during the online step.
    • The addRecordForSync() method registers the server record as part of the action result.
    • The mobile platform reconciles the locally created record with the server-side record. The device and instance remain consistent without creating duplicate records.
    Note:
    The addRecordForSync() method can be called multiple times to register multiple records on different tables or on the same table.