Get Value from Current Row

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I'm trying to set an Action item to update a field in a row, but the row isn't necessarily the top row...

{{$Model.modVendor.data.0.VendorID__c}}

How can I adjust this to capture the VendorID__c field for the current row, rather than the top (0) row?
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Hi Scott, It depends on whether the initiator of your action sequence provides "context".  For instance if your action sequence was initiated by a row action, the action sequence will be run in the context of the row you clicked.  In that case you can use a simplified merge syntax that assumes that there is a row in context.  If you had the correct row in context, your merge would just look like this... {{VendorId__c}}

That being said, where are you initiating your action sequence from?
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
It's a little convoluted, but I have a table (vendors) attached to a master model (rfq).  Inside the vendors table there are drawers which include another table (dims) directly connected to each vendor.  When the user adds a record to the dims model, I need the Name field to be equal to a field (VendorID) from the vendor model.  Since the user may add multiple dims to multiple vendors, I can't just assign the VendorID from the top record of the vendor table.  I tried, {{VendorID__c}}, but it isn't working...  The action sequence is initiated at the "Add new row" action in the dims model.  Any thoughts?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
You'll have to create another model called CurrentVendor. Create one condition where Id = Single Specified Value. Set actions Activate and Set this criteria then query CurrentVendor in your row action just before the drawer action. Then you use {{$Model.CurrentVendor.data.0.Id}} to set VendorID of the record in dims.
(Edited)
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Hi Scott,

I think you may need to write a Javascript Snippet to accomplish what you're trying to do.  I'm not sure that Skuid can do this out of the box.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,764 Points 20k badge 2x thumb
Sure it can. See my post above. Create a model called CurrentVendor. Use action framework on row action to set it prior to drawer.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,774 Points 20k badge 2x thumb
hmmmm .... this is drawer so creating new records in the drawer can't be done this way. If it were a popup then no problem.

Issue is that the user can open multiple drawers. Whichever is the last drawer opened, then it would be set as the CurrentVendor.

3 options I can think.
  1. Switch the drawers to popups and use CurrentVendor model.
  2. Don't use CurrentVendor model, but limit creating new dims to a row action on the vendor. That way you can isolate your merge values to be a row in context. {{VendorId__c}}
  3. Use javascript. :S
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
You're right Pat, you could do this with the action framework, but you might run into issues when multiple drawers are open at the same time.  You could probably move setting the CurrentVendor id condition and CurrentVendor model update into the Action Sequence on the dims model.  That way you'd be sure to get the right Vendor id every time.  Going to the server to get VendorId every time you want to create a new dims record seems a bit wasteful to me since Skuid already knows the Vendor Id of the parent model.  But if writing Javascript is out of the question, then it could be accomplished this way.  

We're thinking about more ways to declaratively specify context throughout the actions framework, but we're not there yet.
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
any input on how to write the JS?
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
nevermind - i figured this out... thanks
Photo of Izunna

Izunna

  • 342 Points 250 badge 2x thumb
Hi Scott, Can you explain how you figured it out?
Photo of Nicholas Playoust

Nicholas Playoust

  • 258 Points 250 badge 2x thumb
I have a similar problem (I think).

I have followed the Mass Create Records tutorial and it works, thank you! (the good news).  However, whereas in the tutorial the AccountId references the current detail record page, in my case I want to trigger the Wizard from a row action that is nested in another Page (with Page Include).

Accordingly, I need to pass the ID of the record in the current row of a table (where there are drawers) through that row action which activates the wizard.  

I cannot get that ID to pass through.  (the bad news). I cannot use {{$Model.CurrentCommitment.data.0.Id}} because it could be from any row.

Any help would be appreciated!  
Photo of Izunna

Izunna

  • 342 Points 250 badge 2x thumb
I have a similar problem as Scott,
I want to attach the account Id of a row in table to the new Opportunity I'm creating. I'm not able to use the action framework because calling {{$Model.Account_List.data.0.Id}} will always give me the first Account ID in the model.
I've decided to us JS as a solution but I'm not able to figure out how to get the ID from the row action 

var params = arguments[0], model = params.model,
row = params.row,
$ = skuid.$;

var newOpp = skuid.model.getModel('NewOpportunity');

//newOpp.updateRow(row,{AccountId: "Test"});

console.log(params);
console.log(model);
console.log(row);

The Above is my attempt to figure out how to reference the specific context row. Any help?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,764 Points 20k badge 2x thumb
You ought to be able to use {{Id}} for the opp and {{Account}} for the associated Account since you have the row context.
Photo of Izunna

Izunna

  • 342 Points 250 badge 2x thumb
Neither of those two worked because I'm creating an Opportunity from a row action on a table of accounts.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,764 Points 20k badge 2x thumb
You're doing it wrong ....

where have I heard that before.

Seriously should work without issue. JS should not be necessary. Creating a new opp from an Account table should work. Did you include the Id field the Account model. You ought to be able to use the Create New Row w/ default values.
Photo of Izunna

Izunna

  • 342 Points 250 badge 2x thumb
Can you please test, Putting in {{Id}} as the value for Update a field on row(s) for my newly created model just gives me a single number
Photo of Izunna

Izunna

  • 342 Points 250 badge 2x thumb
Figured it out. In JS, use var item = arguments[0].item, to refer to the specific Item