Skip to main content

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?

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


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)


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


Thanks for that link Rob, it looks like it’s a step in the right direction. Unfortunately it looks like that’s focused more on creating a bunch of records based off of a user input. I need to basically mirror the data of one object to another. Take a look at my (simplified) data model below.

  • SO_Items__c
    • Sales_Order_Key__c (lookup)
    • Price_Each__c (currency)
    • Quantity_Sold__c (number)
  • Invoice_Items__c
    • Invoice_Key__c (lookup)
    • SO_Item_Key__c (lookup)
    • Price_Each__c (currency)
    • Quantity__c (number)
From the Sales Order page, I’d like them to somehow be able to click a button that takes all the items from SO_Items__c (obviously using conditions to limit to items related to that SO) model/object and create Invoice_Items__c lines that they can edit before saving.

Hopefully that clarifies my goal more.


Sounds like you need javascript to loop through each record while creating a new one based on the current record.


Don’t get hung up on the second step shown in the introduction.  At its base - that tutorial shows how to take all the records in one display (model)  and make corresponding records in another one.  What you lay out is exactly what the tutorial does.   Just skip that step where the user popuplates data in one place that will get applied to all statements. 


I’m a complete dum-dum. Thank-you so much! This was one of the last big hurdles I hadn’t quite figured out about Skuid.

My code wound up being much more simple than the tutorial, so I’ve posted a below for anyone else who comes upon this question. It’s really that simple.

https://gist.github.com/anonymous/026c3d10468634f35cef


Glad to know you got it working!  Have a good party…   Thanks for sharing. 


Rob,

Thank you for your tutorial.  I have laboriously followed it (not really having any idea what I’m doing!) on custom objects and it is working… almost.

My problem is this:

- I’m trying to pull in a second additionalCondition and can’t get it to work.  The equivalent on your tutorial would be to pull in another field from the Contact record.

Any assistance would be appreciated!  Thanks.

Nicholas


Nicholas can you post your snippet, I may be able to help with it.


Moshe,

That would be great if you could.  I’ve made bold the bit that’s not working.  It’s supposed to go the ContractSum record, get a currency value from a field called Current_Claim_ex_GST__c’, and populate the Amount field in the new Claim Detail (CDNewRecord) with that value.  Maybe I need to add some other conditions to the Model?

var params = arguments 0];var step = params.step;
var $ = skuid.$;
// Get references to our three important Models
var models = skuid.model.map();
var ContractSum = models.ContractSum;
var CDPrototype = models.ClaimDetail_Prototype;
var CDNewRecord = models.ClaimDetail_NewRecords;
// Use the values specified in our protoStatement record
// to set conditions on our newStatements model.
// That way, when we auto-generate new statement records,
// these conditions will be used to prepopulate each new Statement.
var proto = CDPrototype.getFirstRow();
var RecordTypeCondition = CDNewRecord.getConditionByName(‘RecordTypeID’);
var ClaimNameCondition = CDNewRecord.getConditionByName(‘ClaimName’);
var CSCondition = CDNewRecord.getConditionByName(‘CS’);
CDNewRecord.setCondition(RecordTypeCondition,CDPrototype.getFieldValue(proto,‘RecordType’));
CDNewRecord.setCondition(ClaimNameCondition,CDPrototype.getFieldValue(proto,‘Claim__c’));
CDNewRecord.setCondition(CSCondition,CDPrototype.getFieldValue(proto,‘Contract_Sum__c’));
// Now, auto-generate a new Claim Details record 
// for each Contract Sum in this Commitment.
$.each(ContractSum.data,function(){
    var row = CDNewRecord.createRow({
        additionalConditions: w
            { field: ‘Contract_Sum__c’, value: this.Id, operator: ‘=’, nameFieldValue: this.Name },
            { field: ‘Amount__c’, value: ContractSum.getFieldValue(ContractSum,‘Current_Claim_ex_GST__c’)}
        ]
    });
});
// We’re good to go - navigate our wizard to Step 2
step.navigate(‘step2’);



OK my initial thought is this: model.getFieldValue() expects a row as the first parameter. It looks like your passing in the model as the first parameter. Try changing the line to this:

{ field: ’ Amount__c’, value: ContractSum.getFieldValue(this, ‘Current_Claim_ex_GST__c’)}

It appears that you are looping through the data of the model so “this” should refer to the current row in the loop. Just to be sure you can add “console.log(this);” inside of the loop and see what value you are getting in the console. Personally I usually would make the loop like so:

$.each(ContractSum.data,function(i, row){
    var newRow = CDNewRecord.createRow({
        additionalConditions: a
            { field: ‘Contract_Sum__c’, value: row.Id, operator: ‘=’, nameFieldValue: row.Name },
            { field: ’ Amount__c’, value: ContractSum.getFieldValue(row,‘Current_Claim_ex_GST__c’)}
        ]
    });
});
 
I think that this loop above will work, but you can stick with “this” if you’d like.


Brilliant!

Thanks Moshe.  I just used “this” and it has worked.  Having set up the Mass Action, I’m still customising it to my pages, so I might have to ask you further questions later! 🙂

Thanks again. Nicholas 


I’m following right up to this point " 
{ field: ‘Contract_Sum__c’, value: row.Id, operator: ‘=’, nameFieldValue: row.Name },

            { field: ’ Amount__c’, value: ContractSum.getFieldValue(row,‘Current_Claim_ex_GST__c’)}

Can somebody break this down for me in its component parts?  Thanks.
James


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).


Moshe, 
Thanks.  Big help.  This is what I have so far:

var params = argumentsn0];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: n
        { 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





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;


Moshe is right, that’s bit me too many times.  You can use Chrome developer tools to set breakpoints and step through the code.


Thanks guys.  Got this up and running.  below is my code for anyone who runs across this thread.

var params = argumentst0];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);
});


// –>