Pass Id to Step 2 in Wizard

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Using the Step Wizard:
I have a list of Lenders in Step 1, with a checkbox need to each of them.
Depending on which Lender is checked, how can I pass the Id (of the Lender) to Step 2 which contains Plans, as I wish to filter Step 2 the Lender selected in Step 1.

I'm not sure how to pass the Id of the selected Lender in Step 1 to Step 2, then filter the table.
Photo of Eddie

Eddie

  • 720 Points 500 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Try something like this as a row action on your lenders table in step 1:

var params = arguments[0],   $ = skuid.$;
var model = params.model;
var row = params.item.row;
// get a reference to the row the user clicked
var Id = row.Id;
// get the Lender Plans Model by it's name
var lenderPlansModel = skuid.$M('LenderPlans');
// get the condition on the model by it's name, (this condition should be filterable default off)
var lenderIdCondition = lenderPlansModel.getConditionByName('NameOfYourCondition');
// set the lender plan model to only show for the selected rows lender
lenderPlansModel.setCondition(lenderIdCondition, Id);
// get a reference to the wizard step
var wizard = $('.nx-wizard').data('object'); 
var currentStep = wizard.steps[wizard.currentstep];
// requery the Lender Plans model with the condition active 
lenderPlansModel.updateData(function(){
//navigate to step 2
currentStep.navigate('step2');
});
Photo of Eddie

Eddie

  • 720 Points 500 badge 2x thumb
Hi Moshe, thanks a lot for the reply, I tried the above but it was unsuccessful, I had already written something similar for the first step below which works:

//get models and conditions
    var QuoteWizardStep2Model = skuid.model.getModel('QuoteWizardStep2');
    var step2LenderIdCondition = QuoteWizardStep2Model.getConditionByName('Step2LenderId');
   
    //Set the QuoteWizardStep2 model's condition to contain the idsOfRowsThatAreChecked, and refresh the model
    QuoteWizardStep2Model.setCondition(step2LenderIdCondition, idsOfRowsThatAreChecked[0], true);
    skuid.model.updateData([QuoteWizardStep2Model]);
   
    //Navigate to Step 2
    var wizard = $('.nx-wizard').data('object');
    var currentStep = wizard.steps[wizard.currentstep];
    currentStep.navigate('step2');



The Snippet I have for Step 2, which needs to take the LenderId and LenderPlanId and these details need to populate the fields in Step 3 which is creating a New Quote doesn't work, my code is below if you have any suggestions, thanks:


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

//Declare variable for the Field to retrieve values from   
var CHECKBOX_FIELD = "Select_Item__c";
var LENDER_FIELD = "Lender__c";
var idsOfRowsThatAreChecked = [];
var idsOfLendersThatAreChecked = [];

//Get Model
var QuoteWizardStep2Model = skuid.model.getModel('QuoteWizardStep2');

   
//Loop through all rows and grab the Id's of the ones checked as Received
$.each(QuoteWizardStep2Model.data,function(i,row){
   if (QuoteWizardStep2Model.getFieldValue(row,CHECKBOX_FIELD)===true){
      
       idsOfLendersThatAreChecked.push(QuoteWizardStep2Model.getFieldValue(row,LENDER_FIELD));
       idsOfRowsThatAreChecked.push(row.Id);
   }
});

if (idsOfRowsThatAreChecked.length > 1){
    alert('You can only Select one Lender');
}
else{
    //get models and conditions
    var QuoteWizardStep3Model = skuid.model.getModel('QuoteWizardStep3');
    //var step3LenderIdCondition = QuoteWizardStep3Model.getConditionByName('Step3LenderId');
    var step3LenderPlanIdCondition = QuoteWizardStep3Model.getConditionByName('Step3LenderPlanId');
   
    //Set the QuoteWizardStep3 model's condition to contain the Lender & Lender Plan, and refresh the model
    //QuoteWizardStep3Model.setCondition(step3LenderIdCondition, idsOfLendersThatAreChecked[0], true);
    //skuid.model.updateData([QuoteWizardStep3Model]);
    QuoteWizardStep3Model.setCondition(step3LenderPlanIdCondition, idsOfRowsThatAreChecked[0], true);
    skuid.model.updateData([QuoteWizardStep3Model]);
   
    //Navigate to Step 2
    var wizard = $('.nx-wizard').data('object');
    var currentStep = wizard.steps[wizard.currentstep];
    currentStep.navigate('step3');
   
    alert(idsOfRowsThatAreChecked);
    alert(idsOfLendersThatAreChecked);
}
Photo of Eddie

Eddie

  • 720 Points 500 badge 2x thumb
Hi Moshe is there a way to pass a param value from one step to another in the Step Wizard. I don't think you can use URL Params?
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Hi, Eddie,

For your situation, I don't think you will be able to pass it just using the actions framework. With the actions framework, you can pass values using global variables, such as {{$Model.QuoteWizardStep2.data.0.Id}} (referring to the first row in the model), but this would require knowing which row's Id to pass ahead of time. I think you're going to have to still use JS. I should point out that the field picker for a wizard button is nonsensical since the wizard is not attached to a specific model... I think we're planning to fix that!



Does that answer your initial question?

As for why the code is not working, you said that the first section of code is working? So, in the first part, are you creating a new row or bringing in existing data that follows the condition you are setting? Also, what kind of error are you getting for the second part?
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Actually, I just saw your other post. Even if your QuoteWizardStep3Model brings in a single, new row on page load, whenever you call updateData() (querying the model), you will bring in existing data that follows your newly set condition (up to the Max # of Records). So, even if your model has a max # of records equal to 1, and you select "Create default row if Model has none" and deselect "Load Model data on page load," whenever you query the model again, your new row will be replaced with a single row from your existing data that obeys the model conditions (whereas you want to create a new row obeying the model conditions). Does that make sense?

So, rather than calling update data, your answer would be:
1) If needed, abandon the current row:
if (QuoteWizardStep3Model.data.length > 0) {
	$.each(QuoteWizardStep3Model.data, function(i, row){
		QuoteWizardStep3Model.abandonRow(row);
	});
}


2) Create your new row
QuoteWizardStep3Model.createRow();

And then proceed with navigating to the next step. I THINK that should work. Give it a try and let me know.
(Edited)
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Note the warnings for abandonRow() in our documentation ... you may want to use removeRowById() instead.