Trigger mass record creation from a page

  • 1
  • Question
  • Updated 5 years ago
  • Answered
I need to trigger creating statement records for clients
so i need a way to put an input field on a page where a user can select a date and click a button to create all the open statements

I'm guessing I'll use a visual force page that will contain the code to create the statements and then do a redirect back to the page where the process starts

so how do i put an "unbound" text box and a button that will launch the request... or do i need to do that in a regular visualforce page ?
Photo of ktyler

ktyler

  • 9,244 Points 5k badge 2x thumb

Posted 6 years ago

  • 1
Photo of ktyler

ktyler

  • 9,244 Points 5k badge 2x thumb
It looks like i could use one of your "wizards" to do this... but there's not much in the docs on them
Photo of Anna Wiersema

Anna Wiersema

  • 10,890 Points 10k badge 2x thumb
OK. I'm not quite sure I understand your question... with Skuid you can create a new record & related/child object records on the same page. The tutorials also show how to use a wizard to create a new Contact + Cases + Appointments Page. Even though the example uses the contact object, it should help get you started on creating a page that will create multiple records across different objects.

Is there anything else you want to be able to do here?
Photo of Anna Wiersema

Anna Wiersema

  • 10,890 Points 10k badge 2x thumb
Never fear - Zach just showed me how to add "Mass Create" using a wizard. I'll try to write up a tutorial and have it posted.... before Monday afternoon.
Photo of Anna Wiersema

Anna Wiersema

  • 10,890 Points 10k badge 2x thumb
This tutorial is up. :D Let me know if you have any further questions / have any issues with the process.
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb
Anna ... that tutorial is great and it suits a use case that I have fairly well. But I can't quite get it working! :)

My scenario is slightly different to the example. In mine:

- user clicks "Generate Tasks".
- system reads records from Process_Steps__c (with fields AssignedTo and Subject), loops through and presents those in an editable table on screen.
- user makes adjustments to field values and hits Save.
- system inserts a Task for each of the records on screen.

I've tried to massage/bastardise/coerce your sample Javascript to meet my needs. It generates the table with the same fields and number of records as Process_Steps__c, but the table cells on the page are blank. Any chance you could point me in the right direction? Have included my Javascript below:

var params = arguments[0];
var step = params.step;
var $ = skuid.$;
// Get references to our important Models
var models = skuid.model.map();
var processSteps = models.ProcessSteps;
var newTasks = models.NewTasks;
// Use the values specified in our processSteps records
// to set conditions on our newTasks model.
// That way, when we auto-generate new task records,
// these conditions will be used to pre-populate each new task.

var procstep = processSteps.getFirstRow();
var ownerCondition = newTasks.getConditionByName('vAssignedTo');
var subjectCondition = newTasks.getConditionByName('vSubject');
newTasks.setCondition(ownerCondition,processSteps.getFieldValue(procstep,'User__c'));
newTasks.setCondition(subjectCondition,processSteps.getFieldValue(procstep,'Subject__c'));

// Now, auto-generate a new task record
// for each process step.
$.each(processSteps.data,function(){
var row = newTasks.createRow({
additionalConditions: [
{ field: 'WhatId', value: '001A000000RA3kE'}
]
});
});
// We're good to go - navigate our wizard to the next step
step.navigate('step3');
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Glenn, if your rows are getting created, but the fields are showing up blank, then I think that the problem is that the Name field for the related records (e.g. the 'What' field) is not getting picked up on during the createRow process. Here's how you can change that --- add a 'nameFieldValue' parameter to your Conditions. Also, make sure you include the operator, so that Skuid knows that it is supposed to use this. In upcoming releases, Skuid will be assuming '=' for additionalConditions, but currently, it requires operator '=' to be explicitly specified.



var row = newTasks.createRow({
additionalConditions: [
{ field: 'WhatId',
value: '001A000000RA3kE',
operator: '=',
nameFieldValue: 'United Oil and Gas'
}
]
});
Photo of Emily Davis

Emily Davis, Employee

  • 3,502 Points 3k badge 2x thumb
Hey, Glen,
This may be what you need (a tip I got from the Skuid developers!). Have you tried the updateRow(row,field,value) method? Might look something like:

$.each(processSteps.data,function(){
var row=newTasks.createRow();
newTasks.updateRow(row, 'WhatId', processSteps.getFieldValue(procstep,'Subject__c'));
});

Not sure if that's exactly right, but hope it helps!
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb
Thanks Zach and Emily.

I've combined your two approaches and would seem to be close. My WhatId and OwnerId are now populating with their respective hard-coded Ids, so that's fine. But I'm trying to populate Subject from the Subject__c field from my ProcessSteps model, but it just populates the table cell with 'null' (screenshot attached). Any thoughts?

var params = arguments[0];
var step = params.step;
var $ = skuid.$;
// Get references to our important Models
var models = skuid.model.map();
var processSteps = models.ProcessSteps;
var newTasks = models.NewTasks;

// Now, auto-generate a new task record
// for each process step.
$.each(processSteps.data,function(){
var row = newTasks.createRow({
additionalConditions: [
{ field: 'WhatId', value: '001A000000RA3kE',
operator: '=', nameFieldValue: 'Morrison Family'
},
{ field: 'OwnerId', value: '005A0000000kLCe',
operator: '=', nameFieldValue: 'Derek Fielding'
}
]
});
newTasks.updateRow(row, 'Subject', processSteps.getFieldValue('Subject__c'));
});
// We're good to go - navigate our wizard to the next step
step.navigate('step3');

Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Glenn,

Your main problem is that you're not passing in the row in your getFieldValue(row,field) call.

You can actually eliminate the updateRow line and just set all your field values in the additionalConditions call:



$.each(processSteps.data,function(i,processStep){
var row = newTasks.createRow({
additionalConditions: [
{
field: 'WhatId',
value: '001A000000RA3kE',
operator: '=',
nameFieldValue: 'Morrison Family'
},
{
field: 'OwnerId',
value: '005A0000000kLCe',
operator: '=',
nameFieldValue: 'Derek Fielding'
},
{
field: 'Subject',
value: processSteps.getFieldValue(processStep,'Subject__c'),
operator: '='
}
]
});
});
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb
Gotcha, that makes sense. And it works! Much appreciated.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Is it possible to mass create children from an inline scenario, maybe through a popup action? is there Context in a parent table, to be able to mass create child records inline?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
This should be possible via some JavaScript, can you give a little more detail? The way I understand it, perhaps you have an Opportunities table, and you want to have a Row Action on the Opportunity that would mass-create Line Items for the particular Opportunity, or Quotes, or something like that? And show them in a Popup table?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
var params = arguments[0];
var step = params.step;
var $ = skuid.$;
// Get references to our three important Models
var models = skuid.model.map();
var Index = models.Index;
var protoPricing = models.ProtoPricing;
var newPricing = models.NewPricing;
// 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 = protoPricing.getFirstRow();
var EffectiveDate = newPricing.getConditionByName('Effective_Date__c');
newPricing.setCondition(EffectiveDate,protoPricing.getFieldValue(proto,'Effective_Date__c'));
// Now, auto-generate a new Statement record
// for each Contact in this Account.
$.each(Index.data, function(i, indexRow){
var row = newPricing.createRow({
additionalConditions: [
{ field: 'Index__c', value: this.Id, operator: '=', nameFieldValue: this.Name }

]
});
});
// We're good to go - navigate our wizard to Step 2
step.navigate('step2');

Here's my JavaScript, it's working fine. However I want to populate a child column as I'm looping through the parent, and creating children for every parent. Basically, I wanted to add an additional condition that looked like this:

{ field: 'Rate__c', value: indexRow.Index_Pricing__r.Rate__c, operator: '='}

However I can't get to the Rate__c field through this syntax.
Is there a way for me to populate every child row created, with specific child data for every parent? Is there a different syntax I can use to get the child field?