My Javascript is very “beginner” at this point. Could someone tell me the syntax for a snippet that would add a row to a table (Model , capture data from a field editor field (Model A), and update the new row with said data? It will actually be multiple fields, but I think I can adjust the code if someone can give me a head start… thanks so much for any help on this!
Something like this will work… I left in the fields that I was using to give you an idea of how it works:
var $ = skuid.$;var modelA = skuid.model.getModel('ModelA');<br>var modelB = skuid.model.getModel('ModelB');<br>var row = modelA.getFirstRow();<br>modelB.createRow({<br>additionalConditions:s<br>{field: 'Utility_Account__c', value: row.Utility_Account__c, nameFieldValue: row.Utility_Account__r.Name},<br>{field:'Utility_Account_Number__c', value: row.Utility_Account_Number__c},<br>{field:'LDC2__c', value: row.LDC2__c, operator:'=', nameFieldValue: row.LDC2__r.Name},<br>{field:'Billing_Group__c', value: row.Billing_Group__c},<br>{field:'Opportunity__c', value: row.Opportunity__c}<br>]<br>});
Though I’m grateful for Moshe’s sharing, I think you are jumping to code more quickly than you need to. I think you can create this functionality with the action framework and not have to use any code.
First make sure you have at least version 5.13 of skuid installed. Some key features were introduced with that version.
Drag a page title component into the vicinity of your field editor. This page titile shoudl be associated with the same model as your field editor (Model A). Add a button to the page title of type “Run multiple actions”
Action1: Create a new row in model. Choose Model B.
You will notice a new icon by the action type labled “Add Default Value”. Add as many of these actions as you need to prepopulate your data.
Action 2: Save Model B
Action 3: Requery Model B
Hope this works for you.
Hey Rob sorry for not promoting the action framework… I really need to start using it more. That add default value button looks great!
No worries Moshe. The code solution works just as well. When you are comfortable with a tool there is nothing wrong with using it…
Hey Guys -
First off, thanks for the help!
I must not have 5.13 yet, because I don’t have access to the default option. I will be upgrading soon, but for now I need the JS. I’ve tried Moshe’s code, but I can’t seem to get the value of the field I need. Any suggestions? Does the field name need to be different in each model? I seem to only be capturing the ID number of the field…
var $ = skuid.$;var modelA = skuid.model.getModel(‘modRFQ’);var modelB = skuid.model.getModel(‘modVendor’);
var row = modelA.getFirstRow();
modelB.createRow({
additionalConditions:
{field:‘Hanger__c’, value: row.Hanger__c, operator:‘=’, nameFieldValue: row.Hanger__r.Name}
]});
Is Hanger__c a lookup field? What context are you running the snippet from (page title, row action, mass action…) ? What do you mean the " ID number of the field"? Try this to help you debug:
var $ = skuid.$;var modelA = skuid.model.getModel('modRFQ');var modelB = skuid.model.getModel('modVendor');<br>var row = modelA.getFirstRow();<br>var newRow = modelB.createRow({<br>additionalConditions:n<br>{field:'Hanger__c', value: row.Hanger__c, operator:'=', nameFieldValue: row.Hanger__r.Name}<br>]}); //use Ctrl + Shift + J to open the javascript console in chrome //see if anything is undefined or any errors etc console.log(newRow); console.log(row);
Hanger__c is a lookup field in Model A, but it is only a text field in the table (Model . The Snippet is being run from a Page Title button attached to Model A. As for the ID number, this is what I’m getting: a1PL00000024ldzMAA…
OK that’s a little tricky, If you only want the name to display in model B, you can do this…
var $ = skuid.$;var modelA = skuid.model.getModel(‘modRFQ’);var modelB = skuid.model.getModel(‘modVendor’);
var row = modelA.getFirstRow();
modelB.createRow({
additionalConditions:l
{field:‘Hanger__c’, value: row.Hanger__r.Name}
]});
No, no… I definitely want the value selected for Hanger__c in Model A… right now I’m only getting the RecordID I believe. Basically, Model A - Hanger__c has a value of Hanger001. I need this value to default to Model B - Hanger__c…
Ok make sure you selected Hanger__r.Name in model A and console.log(row.Hanger__r.Name) and see what you get…
Got it!
Awesome… thanks Moshe!
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.