- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 04:21 PM
Hello Community,
I'd like to create a button that upload data into MRVS from an attachment with widget.
But I face the issue of 'Server JavaScript error Cannot read property "action" from undefined';
Could someone teach me how to solve it?
It is being prepared based on this article.
https://www.servicenow.com/community/itsm-forum/convert-ui-macro-to-widget/m-p/2431768
If I resolve that issue, I would like to add csv data to mrvs 'post_transfer_request_variable_set (sysid: d1f902b31bbc42d0f078a60ce54bcb12)'.
HTML
<div>
<div><label>GlideAjax</label> <input ng-click="c.applyVariablesAjax()" type="button" value="${Apply Data}" /></div>
</div>
Client Script
api.controller = function ($scope) {
var c = this;
c.applyVariables = applyVariables;
c.applyVariablesAjax = applyVariablesAjax;
console.log('getCartID', getCartID());
function applyVariables () {
var cartID = getCartID();
c.server.get({
'action': 'get-CSV-data',
'cartID': cartID,
}).then(receiveCSVData);
}
function applyVariablesAjax () {
var cartID = getCartID();
var ga = new GlideAjax('global.MRVUtils');
ga.addParam('sysparm_name', 'getCSVData');
ga.addParam('sysparm_cart_id', cartID);
ga.getXML(processResponse);
}
function getCartID () {
return getTableIdOrParentScope($scope);
}
function getTableIdOrParentScope (scope) {
return typeof scope.attachmentHandler != 'undefined' ?
scope.attachmentHandler.tableId :
typeof scope.$parent != 'undefined' ? getTableIdOrParentScope(scope.$parent) : '';
}
function processResponse (response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
console.log('test_multi_row', answer);
$scope.page.g_form.setValue('test_multi_row', answer);
}
function receiveCSVData (response) {
console.log('test_multi_row', response.data.list_of_participants);
$scope.page.g_form.setValue('test_multi_row', response.data.list_of_participants);
}
};
Server Script
(function ($sp, data, input) {
if (input.action == 'get-CSV-data'){
data.list_of_participants = new global.MRVUtils().getCSVData(input.cartID);
}
})($sp, data, input);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:00 PM
Hi @110100
Try with below Server Script :
(function ($sp, data, input) {
if (input) {
var localInput = input;
if (localInput.action == 'get-CSV-data'){
data.list_of_participants = new global.MRVUtils().getCSVData(localInput .cartID);
}
})($sp, data, input);
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:00 PM
Hi @110100
Try with below Server Script :
(function ($sp, data, input) {
if (input) {
var localInput = input;
if (localInput.action == 'get-CSV-data'){
data.list_of_participants = new global.MRVUtils().getCSVData(localInput .cartID);
}
})($sp, data, input);
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:23 PM
Hi @Amit Verma
Thank you for your support!
I tried it and it works fine.
I really appreciate you.
It is still moderating, but if you have time, I would appreciate it if you could take a look at the question following the link (the issue with the extracted value being [] of same code).
<a href = "https://www.servicenow.com/community/developer-forum/how-to-inject-mrvs-to-data/m-p/28687...https://www.servicenow.com/community/developer-forum/how-to-inject-mrvs-to-data/m-p/2868712#M1096077</a>
Sincerely,
110100
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:25 PM
Hi @Amit Verma
Thank you for your support!
I tried it and it works fine.
I really appreciate you.
It is still moderating, but if you have time, I would appreciate it if you could take a look at the question following the link (the issue with the extracted value being [] of same code).
https://www.servicenow.com/community/developer-forum/how-to-inject-mrvs-to-data/m-p/2868712#M1096077
Sincerely,
110100