Display message or redirect to a child page when updating field

Hey all,

I have a status field in a table, when the user changes the status to ‘returned’ i’d like to either show a message reminding the user to add a connected record or ideally redirect them to the existing child page which is a modal so they are forced to add it.

To add context when an order is shipped the user clicks an action link to add a connected record to add the delivery charge and delivery method. Once the info is submitted the order status is updated to shipped and the action link is hidden so extra charges cant be added by mistake. If the item is returned we add a further charge for handling this so the existing child page would do the job nicely. If i just allow the link to be displayed again i then have to handle the link being disabled again once the return charge has been added!

as always, thanks in advance

So i’ve hashed this together using bits of code from the javascript examples and it mostly works.

the field being updated is a dropdown, can anyone tell me how to only have it run when a specific option is selected in the dropdown?

// Update record with child page on field update
// Replace view_xx with the view key for the table view in question
// Replace field_yy with the field key for the field whose changes you want to track
$(document).on('knack-records-render.view_11', function(event, scene, records) {
  $(document).on('knack-cell-update.view_11', function(event, view, updatedRecord) {
    var recordID = updatedRecord.id
    // Filter the initially loaded records for the one with the same ID as the updated one
    var recordBeforeUpdate = records.filter(recordFromRenderEvent => {
      return recordFromRenderEvent.id === updatedRecord.id;
    })[0];

    if (updatedRecord.field_11 !== recordBeforeUpdate.field_11) {
      // Do something, such as:
      window.location.replace('https://psymonbeesley.knack.com/untitled-app-2#manage-orders/add-shipping-charge/'+recordID);
    }

    $(this).off(event)
  });
});

I ended up trashing the idea and built a way of doing it natively in knack and in the process have manged to almost eliminate the need to manually update status using rules… its amazing what hitting a problem can do for creative thinking! lol

1 Like