Use new record ID in condition on another model

I am trying to render a list of records (model = MedRecs) using the ID field of newly created record (model = Shipment) as a Condition.

My first model is called Shipment.  Because I want to create a new Shipment record, I’ve set “Create Default Row if Model Has None” to TRUE and “Load Model Data on Page Load” to FALSE.  Max # of Records = 1.  The user fills in some fields for the Shipment model and saves.  

My second model is called MedRecs.  MedRecs are displayed in a table below the Shipment field editor.  The table is conditionally rendered: it does not show up until the new Shipment record has been saved. 

When the MedRec table does show up, I only want it to display records where a lookup field on the MedRec (MR_Holder__c) matches a lookup field on the new Shipment record (Ship_From__c).  I’ve tried to build the MedRec condition many different ways: MR_Holder__r.Id = (Shipment)(Ship_From__r.Id); MR_Holder__c = (Shipment)(Ship_From__c).  

If I set “If no row in Source Model, then…” to “Abort this model’s query”, I see no MedRecs.  If I set it to “Deactivate this Condition,” I see all the MedRecs.  

So - why isn’t the new Shipment identified as a row in the Source Model?  I created a second table on the page that, like the MedRec table is conditionally rendered - it only shows up when the new Shipment record has been saved.  This table has the “Shipment” model as its source model, and it shows the single new Shipment record.  

I’d appreciate feedback on what I’ve done wrong here - thanks for the help.

Hi, Elissa,
It looks like you’re doing everything right so far. However, Skuid is not updating your MedRecs model the page is refreshed. In the words of Ben Hubbard, “Unfortunately as of yet, Skuid will not automatically update “Field from another Model” type conditions when their source model is updated” (see this post… it might be helpful to you). There is a workaround, but it’s a little more complicated.

What you have to do:

  • On your MedRecs model, remove your condition and add a new one that is filterable and off by default. Give your condition a name, and leave the value field empty.
  • Create a custom button for your users to click after entering Shipment information. This button will save the Shipment model, set the MedRecs condition’s value to the Ship_From__c value from the Shipment model, and bring in data to the MedRecs model. 
  • The snippet for your custom button should look something like this:

var $ = skuid.$; //get models and conditions var shipmentModel = skuid.model.getModel('Shipment'); var medrecModel = skuid.model.getModel('MedRecs'); var medrecCondition = contactModel.getConditionByName('MyMedRecCondition'); //After the user enters data on the Shipment, save Shipment model shipmentModel.save({callback: function(){ //get the new shipment var shipment = shipmentModel.getFirstRow(); //Set the MedRecs model's condition to contain the AccountId from the new Shipment, and refresh the model medrecModel.setCondition(medrecCondition, shipment.AccountId); medrecModel.activateCondition(medrecCondition); medrecModel.updateData(); }});


See how this works!
Emily

That worked!  Just what I needed - thank you!

Is this approach still valid for the latest version? Must it be done in JavaScript, or can a “Multiple Action” button do the same job? I’m running Superbank.

The action framework can now do this,  but it requires a little rearranging. 

1. Remove the condition on your secondary model. 
2. Add an action sequence - either to the primary model as a “on save” action, or tied to the save button that saves the primary model data. 
3. The actions will do the the following. 
- Save the primary model.
- Requery the primary model. 
- Create a row on the secondary model. 
- Prepopulate that row with the ID from the primary model.  (Prepopulation is a seconary action under Create new row)

I believe that should do the trick. 

Hi Rob, 

I’ve been playing with this functionality a lot, and tried to use the action framework instead of my snippet, with no success.  If my primary model is designed for a “create new record” page (“Create new row if model has none”=TRUE and “Load model data on page load”=FALSE), the primary model disappears when I requery it.  I’ve tested this by changing the “no row in source model” setting on the secondary model.  If I prepopulate the secondary model with the ID from the primary model and set “no row in source model” to “deactivate this condition”, then many records load into my secondary model.  If I set “no row in source model” to “abort this model’s query,” I get nothing in my secondary model. Note that I’m not actually using the Record ID of the primary model - I want the ID of another lookup field on the primary model in order to display existing records with a lookup that matches the lookup on my primary model. 

Any thoughts on this?  I have tried creating a separate model that corresponds to the “new record” model, but I haven’t been successful.

Hard to tell exactly what you are doing  (This is complicated stuff).   But my sense is that you have a problem with the condition you are passing into your secondary model.  Are you sure that data is in your primary model?  If you put a message in your action sequence that displays the vlaue passed into the condition - does anything show?  (that’s a decent debugging hack). 

If you are still not getting any joy would you mind giving us login rights to your org so we can take a look at what is going on?   Here is how: 1. Use this tutorial to give us login rights: http://help.skuidify.com/m/getting-started/l/182412-getting-help-how-to-grant-skuid-login-rights-to-…

2. Then send an email to support@skuidify.com  with your org Id and the name of the page where the problem is happening and the specific steps needed to repro the problem  (Including a record we can test with). 

We’ll see what’s going on…