I’d like to create a button that creates a new row using another as it’s template. All fields except the name field would duplicate. The name field would be incremented by number or letter. ie. “Room 101” would be “Room 102”, or “Section A” would be “Section B”.
I certainly have to use javascript, but not too sure how get there. Here is the function I have so far.
function CreateIncRow(modelid){ var model = skuid.model.getModel(modelid); var lastrow = ; //(will need to know how many rows there are in order to get the last row. Not sure how to select row by index though) var lastrowlocationname = model.getFieldValue(lastrow,'Location_Name__c'); var lastword = lastrowlocationname.split(" ").pop(); If (!IsNan(lastword)){ updatedlastword = lastword++; } else { var lastwordlastchar = lastword.slice(-1); var lastwordlastcharIncrement = String.fromCharCode(lastwordlastchar.charCodeAt() + 1); var updatedlastword = lastword.substring(0,lastword.length - 1).concat(lastwordlastcharIncrement); } var newrow = model.createRow({ additionalConditions: [ { field: 'Location_Name__c', value: updatedlastword } //Other fields and values here ], doAppend: true }); }<br>
Need help with a few things.
- How do get the row count of a model?
- How do get the last row using an index?
- Why am I getting this error below?
