- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 04:11 PM
Hi Experts, our team is creating a widget in SP that incorporates AngularJS Material. The widget pulls up a dialog box (modal window) that displays a form and when a user submits it, we would like the info they put into each input box to map to the table. Our submit button has an ng-click:
<md-button ng-click="submit()" class="md-raised md-primary">
Submit <i class="material-icons" style="vertical-align:middle;">send</i>
</md-button>
But we are unsure how to code the client script and server script so that the input values get mapped back to the table...
Here's our client script so far:
$scope.submit = function() {
$scope.server.get({
action: 'save_answer'
}).then(function(response) {
});
}
We also started our server script, but nothing works. I'm pretty sure our syntax is incorrect somewhere, but am unsure...
if (input && input.action == 'save_answer') {
var answers = new GlideRecord('questionnaire_table');
answers.query();
answers.initialize();
answers.ref_user = data.user;
for(var i=0; i<sections.length; i++){
for(var j=0; j<section_elements.length; j++){
var key = sections[i].section_elements[j].section_element_name;
var answer = sections[i].section_elements[j].answer;
answers['' + key] = answer;
}
}
answers.insert();
}
We are trying to avoid mapping each input box explicitly back to the table, but instead want to loop through each element name by querying sys_dictionary and sys_ui_section tables and completing it that way. Any suggestions on how to accomplish this efficiently?
Additionally, we have a couple business rules incorporated on the backend form that shows/hides certain fields based on other answers. Is there an easy way to have those transfer over to the widget as well?
THanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2017 04:08 AM
Hi
The elements/inputs in form you display to the user in the dialog, should be named so they match the names of the fields in the table you want to save the values to.
You then push all the input fields to the data object and send it to the server.
On the server you loop through all the object and map the values to the gliderecord
var answers = new GlideRecord('questionnaire_table');
answers.initialize();
for (var key in input.formInput) {
answers.setValue(key,input.formInput[key]);
}
answers.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2017 10:47 PM
Hi
If you know the sys_id of the record you want to update the most direct way to get that record is
var answers = new GlideRecord('questionnaire_table');
answers.get("sys_id of record");
If you don't have the sys_id but another unique field you can do
answers.get("name of uniqe field","value"); //This line returns false if it cannot find a matching record
Then update the fields and end with a
answers.update();
NB: You don't need the answers.query(); when creating a new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2019 02:10 AM
Hi @yundlu316
Could you please help he how to add the Angular JS material dependencies in the portal widget. The <md-datepicker> and <md-button> is not working for me.