Populate a model with rows from another model?

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Here's the scenario: We have a Sales Order with Sales Order Items (related list). I'm trying to create a pop-up on the Sales Order that populates an Invoice Items model with the rows from Sales Order Items, allowing them to change a Quantity Invoiced field that then creates an Invoice and Invoice Items when saved.

I can't quite figure out how to pre-populate the Invoice Items model with data from the Sales Order Items model. Right now I've got it populating Invoice Items with the first row of Sales Order Items, but can't seem to get it to populate all of them. Any ideas?
Photo of Charles Zink

Charles Zink

  • 388 Points 250 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Charles,
So you are actually creating new rows in the Invoice Items model and populating some fields with values from a Sales Order Item, using a row action? In this case, you can add filterable conditions to your Invoice Items model corresponding to the fields you want to populate. Then, use the action framework for your row action to set these model conditions based on field values from the Sales Order Item row in context (using mustache syntax, such as {{Name}} or {{MyCustomField__c}}). For a row action, this should get field values from the row in context rather than the first row in the model. After these conditions are set and activated, any new rows created in the Invoice Items model will have fields prepopulated to follow these conditions. Does that help you out? Let me know if I'm not understanding your question correctly!
Emily
Photo of Charles Zink

Charles Zink

  • 388 Points 250 badge 2x thumb
Hey Emily,

I think you're understanding my question correctly, I'm just lost on understanding your answer! Action framework is the one thing I haven't really had a need to familiarize myself with yet.

So I create a custom row action that sets model conditions? Would that be done with the "Activate and set value of model condition" action type? If so, I'm not able to see my Invoice Items conditions for some reason. (see attached)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Charles.   I actually don't think the route Emily sketched out for you will work.  Sorry about that. 

However we did write a tutorial some time ago that I think will do the trick for you.   Check this out:  Mass Create Records
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Check this out:



And then read the doc on conditions : http://help.skuidify.com/m/11720/l/210439?data-resolve-url=true&data-manual-id=11720 . Basically your adding conditions onto the newly created row. conditions are key->value objects with field->API Name and value->Desired Value. nameFieldValue->Name is a special parameter for lookup fields which indicates what text to display (instead of the literal ID).
Photo of James Bujold

James Bujold

  • 112 Points 100 badge 2x thumb
Moshe, 
Thanks.  Big help.  This is what I have so far:

var params = arguments[0];var step = params.step;var $ = skuid.$;
// Get references to  Models
var models = skuid.model.map();
var newSteps = models.newSteps ;
var checkTemp = models.checklisttemplate;
var checkTempStep = models.checkTemplateStep;

var  rowTemp = checkTemp.getFirstRow();
    

//parse through each template step and create step in newSteps Model

$.each(checkTempStep.data,function(){
    var row = newSteps.createRow({
         additionalConditions: [
        { field: 'Name', value: checkTemplateStep.getFieldValue(this,'Name') },
        { field: ' Assigned_To__c', value: checkTemplateStep.getFieldValue(this,'Assigned_To__c')},
        { field: ' Sequence__c', value: checkTemplateStep.getFieldValue(this,'Seqence__c')},
        { field: ' Comments__c', value: checkTemplateStep.getFieldValue(this,'Comments__c')}
         ]   
    });console.log(this);
});


This is what Im getting from the console: Uncaught TypeError: Cannot read
property 'createRow' of undefined
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
The model names are case sensitive. Your model is probably called NewSteps. For all of your models make sure they're spelled right and with the correct case.

var newSteps = models.NewSteps;
(Edited)
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Moshe is right, that's bit me too many times.  You can use Chrome developer tools to set breakpoints and step through the code.
Photo of James Bujold

James Bujold

  • 112 Points 100 badge 2x thumb
Thanks guys.  Got this up and running.  below is my code for anyone who runs across this thread.

var params = arguments[0];var step = params.step;var $ = skuid.$;
// Get references to  Models
var models = skuid.model.map();
var newSteps = models.newChecklistStep ;
var checkTemp = models.checklisttemplate;
var checkTempStep = models.checkTemplateStep;
var entity = models.Entities;

var  rowTemp = checkTemp.getFirstRow();
var entRow = entity.getFirstRow();

//parse through each template step and create step in newSteps Model

$.each(checkTempStep.data,function(){
    
     if(this.Assigned_To__c === undefined) //if step is not assigend to advisor use secondary advisor of client.
    {determine = entity.getFieldValue(entRow,'Secondary_Advisor__c');} 
    else{determine = checkTempStep.getFieldValue(this,'Assigned_To__c');}
    
    var row = newSteps.createRow({
   
         additionalConditions: [
        { field: 'Name', value: checkTempStep.getFieldValue(this,'Name') },
        { field: 'Assigned_To__c', value:determine},
        { field: 'Sequence__c', value: checkTempStep.getFieldValue(this,'Sequence__c')},
        { field: 'Comments__c', value: checkTempStep.getFieldValue(this,'Comments__c')}
    //    ,{field: 'Completed__c', value:'NO'}
         ]   
    });console.log(this);
});


// --> 
 
(Edited)