Create New Row - Custom Snippet

Hello,

I’m trying to do create new row snippet with the use of tutorial:
http://help.skuidify.com/m/components/l/109496-mass-create-records

and I would like to ask you for help. Thank you in advance. 

The goal is to select accounts or contact from one skuid table (mass action), select the corresponding campaing (built on custom object) and load the accounts or contacts to the object campaign membership (built on custom object). 

The corresponding model are as follow:
a) Accounts;
b) Sales Plan; 
c) Sales Plan Membership (with filterable default off field Account); 

Actions used are: 
a) Mass Action that triggers pop-up showing Sales Plans and Row Action on Sales Plan table that create new row in Sales Plan Membership, populating lookup Sales_Plan__c with {{Sales_Plan_c.Id]]
b) Run Custom Java Snippet in the form of: 

var params = arguments[0], $ = skuid.$;
var $ = skuid.$;
    var model = params.model,
        list = params.list,
        selectedItems = params.item ? [params.item] : list.getSelectedItems();
var models = skuid.model.map();
var Account = models.Accounts;
var SalesPlanMembership = models.SalesPlanMembership;
            
$.each(Account.detail,function(){
    var row = SalesPlanMembership.createRow({
        additionalConditions: [
            { field: ‘Account__c’, value: this.Id, operator: ‘=’, nameFieldValue: this.Name}]
});
});

Could you please give me a hint? 

Best regards.

Jakub, First thing I noticed is that $.each(Account.detail, function(){ … } should be $.each(Account.data, function(){…} Irvin

Also, I am not familiar with this syntax: operator: ‘=’, nameFieldValue: this.Name}. Take a look here how to properly use the createRow() method: http://help.skuidify.com/m/11720/l/129014-skuid-model

Hello Irvin, thanks for you reply. I tried to follow you suggestion but nothing has been changed. 

The function looks like this:
$.each(Account.data,function()
{    var row = SalesPlanMembership.createRow({
        additionalConditions: [
            Account_Membership__c = Account.Id]});
});

Try this:

var params = arguments[0];var $ = skuid.$;
var models = skuid.model.map();
//make sure the model name is spelled right. is it Account or Accounts?
var Account = models.Accounts;
//see what you get in the console
console.log(Account);
var SalesPlanMembership = models.SalesPlanMembership;
            
$.each(Account.data, function(i, row){
    var newRow = SalesPlanMembership.createRow({
        additionalConditions: [
            { field: ‘Account_Membership__c’, value: row.Id, operator: ‘=’, nameFieldValue: row.Name }
        ]
});
});

Hi Moshe, Sorry for the late reply, but I didn’t noticed that you have replied to this post. Well I tried both ways (presented by you and by Irvin) and it didn’t worked. 

The good news is that rows are created but Account_membership__c is not populated. 

The final version of the snippet is as follow (I even changed the names of the models in order to double check it): 

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

    var model = params.model,
        list = params.list,
        selectedItems = params.item ? [params.item] : list.getSelectedItems();
var models = skuid.model.map();
var ParentAccounts = models.ParentAccounts;
console.log(ParentAccounts);
var Membership = models.Membership;
            
$.each(ParentAccounts.data, function(){
    var row = Membership.createRow({
        additionalConditions: [
            { field: ‘Account_Membership__c’, value: this.Id, operator: ‘=’, nameFieldValue: this.Name}]
});
});

Do you see my mistake?

You got to give some more detail about what exactly isn’t working, try some console.log()'s and then check it out in the console (Ctrl + Shift + J in Chrome) and see what you’re getting.

$.each(ParentAccounts.data, function(){
    console.log(this);
    var row = Membership.createRow({

        additionalConditions: [
            { field: ‘Account_Membership__c’, value: this.Id, operator: ‘=’, nameFieldValue: this.Name}]
    });
    console.log(row);
});

The code looks ok to me. One thing to check would be that field names are case-sensitive in Javascript.  Make sure that ‘Account_Membership__c’ is actually the field name, and not something like ‘Account_membership__c’

Ben -> you’re right that it should be m instead of M i.e. Account_membership__c. 

Moshe -> thank you for the attributes for console logs. 

I think we’re close, but still the field is not populated. Look:

Object {Id: “4”, Id15: “4”, Account_membership__r: Object, Account_membership__c: “00124000008RYwWAAW”}Account_membership__c: "00124000008RYwWAAW"
Account_membership__r: Object
Name: "Test Account"
proto: Object
Id: "4"
Id15: "4"
proto: Object

The Name and Id ok. But it is not empty on this Account_membership__c. 

Can you explain your last sentence? What exactly is wrong?

Yes, of course.

Please see:

Log:
Object {Id: “4”, Id15: “4”, Account_membership__r: Object, Account_membership__c: “00124000008RYwbAAG”}

  1. Account_membership__c: “00124000008RYwbAAG”

  2. Account_membership__r: Object

  3. Name: “New Test Account”

  4. __proto__: Object

  5. Id: “4”

  6. Id15: “4”

  7. __proto__: Object
    Id of Account and Name of Account is ok.

But please find that the newly created row and field Account_membership__c is empty.

Hello, maybe someone from you guys can help me with this ? :slight_smile: