Calling Server script from Client script in Declarative action (Related list)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
I have searched this forum for guidance on how to call a server script from client side. Lot's of good material, but still I can't get it to work.
I have a server side script that works:
// create a new record in 'Agenda Topic' with the following data: Document = sys_id, type = sub_item
var gr = new GlideRecord('x_snc_meeting_cr_0_agenda_topic');
gr.initialize();
gr.title = current.document.x_snc_meeting_cr_0_project.getDisplayValue();
gr.type = 'item';
gr.meeting = current.x_snc_meeting_cr_0_meeting;
gr.duration = 60;
var itemId = gr.insert();
// Check the result
if (itemId) {
gs.info('SUCCESS: New record created with Sys ID: ' + itemId);
} else {
gs.error('ERROR: Failed to create a record.');
}
function onClick() {
// 1. Get user input (e.g., using a built-in function or a custom modal)
var userInput = prompt('Enter duration:');
if (!userInput) return;
// 2. Prepare and send the request via GlideAjax
var ga = new GlideAjax('LECreateMeetingAgendaItem');
//ga.addParam('sysparm_name', 'processUserInput');
ga.addParam('sysparm_user_duration', userInput);
ga.addParam('sysparm_project', g_form.getValue('document.x_snc_meeting_cr_0_project').getDisplayValue());
ga.addParam('sysparm_meeting', g_form.getValue('x_snc_meeting_cr_0_meeting'));
// 3. Send the request
ga.getXMLAnswer(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.addInfoMessage(answer); // Show the server's response
}
}
var LECreateMeetingAgendaItem = Class.create();
LECreateMeetingAgendaItem.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
processUserInput: function() {
var inputDuration = this.getParameter('sysparm_user_duration');
var inputProject = this.getParameter('sysparm_project');
var inputMeeting = this.getParameter('sysparm_meeting');
var gr = new GlideRecord('x_snc_meeting_cr_0_agenda_topic');
gr.initialize();
gr.title = inputProject;
gr.type = 'item';
gr.meeting = inputMeeting;
gr.duration = inputDuration;
var itemId = gr.insert();
// Check the result
if (itemId) {
gs.info('SUCCESS: New record created with Sys ID: ' + itemId);
} else {
gs.error('ERROR: Failed to create a record.');
}
return 'Success.';
},
type: 'LECreateMeetingAgendaItem'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Lars Egelund ,
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
37m ago
Thanks, makes sense. However, it didn't make any difference...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
are you in custom scope and UI action and script include both are in same scope?
share screenshots.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
36m ago