Data not getting inserted via Widget for custom table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 04:08 AM
Hello Everyone,
I have created a widget which will insert a record in scoped custom table. In this widget, im using a post call, on click of button, im inserting a record.
Somehow when i use table name as incident, record is getting inserted. But when i replace table with scoped custom table, record are not getting triggered
-------------------Client script------------------------
c.uploadAndSubmit = function($event) {
$event.stopPropagation();
var $el = $element.find('input[type=file]');
$el.val(null);
$el.click();
};
$scope.setAndSubmitFile = function(element) {
if (element.files.length === 0) return;
var file = element.files[0];
$http.post('/api/now/table/x_custom_table', {
short_description: 'record from portal widget'
}).then(function(response) {
var recordSysID = response.data.result.sys_id;
alert('record created. You will receive email shortly.' + recordSysID);
// Step 2: Upload file as attachment
c.uploadAttachment(file, recordSysID);
}, function(error) {
//alert('Error creating record: ' + (error.data.error.message || 'Unknown error'));
});
};
-------------HTML----------------
<td> <button class="btn" ng-click="c.uploadAndSubmit($event)">
Create record
</button> <input type="file" accept=".pdf" style="display:none" id="fileToUpload"
onchange="angular.element(this).scope().setAndSubmitFile(this)" /></td>
</tr>
.
Can someone help me where im missing?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 04:43 AM
Hi @sunilsargam
what have you done so far to identify the root cause? Have you checked the browser console for any errors or the syslog? And apart from that, there are tons of reasons that could prevent inserting a record in your custom table. For example, mandatory fields you are not sending. Therefore, without any further details of your implementation, it's not possible to help you.#
Maik