- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:34 AM - edited 03-01-2024 03:46 AM
Hi All,
I have tried to write a very simple client script and script include which will simply show a message when the priority value changes on an incident record. This is just for testing purposes.
Could anyone point out what I have got wrong here as the alert always provides an answer of null and the log in the script include is not seen.
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Check if the updated field is priority
// Call the server-side function to handle priority update
var ga = new GlideAjax('IncidentScriptInclude');
ga.addParam('sysparm_name', 'priorityUpdated');
ga.getXMLAnswer(priorityanswer);
}
function priorityanswer(answer) {
alert('Message from server: ' + answer);
}
Script include:
var IncidentScriptInclude = Class.create();
IncidentScriptInclude.prototype = {
initialize: function() {
},
// Function to be called when priority field is updated
priorityUpdated: function() {
gs.info('Priority field updated on incident record');
return "success";
},
type: 'IncidentScriptInclude'
};
Any help would be greatly appreciated
Alex
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:59 AM
this will fix it
1) your script include is marked client callable but the syntax it has is for server side i.e. it has initialize function
2) update as this -> remove initialize()
var IncidentScriptInclude = Class.create();
IncidentScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
priorityUpdated: function() {
gs.info('Priority field updated on incident record');
return "success";
},
type: 'IncidentScriptInclude'
});
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
03-01-2024 03:44 AM
Hi @Alex319,
try without the “global” in addParam.
- Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:47 AM
Hi AshishKMishra,
No luck unfortunately. Same outcome. I have updated the script in the post to reflect this.
Thanks
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 03:55 AM - edited 03-01-2024 04:00 AM
Hi @Alex319 ,
Make your Script Include Client callable (check client callable),
var IncidentScriptInclude = Class.create();
IncidentScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// Function to be called when priority field is updated
priorityUpdated: function() {
gs.info('Priority field updated on incident record');
return "success";
},
type: 'IncidentScriptInclude'
});
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2024 04:10 AM
Hi @Alex319 ,
Did you get a chance to look at my solution ? which was given earlier.
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang