Client script and script include help

Alex319
Giga Guru

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:

Alex319_0-1709292700383.png

 

 

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:

Alex319_1-1709292770805.png

 

 

 

 

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'
};

 

 

 

 

Alex319_2-1709292809216.png

Any help would be greatly appreciated
Alex

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Alex319 

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'
});

AnkurBawiskar_0-1709294353790.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Umesh Dubal
Giga Expert

Hi @Alex319 
I have checked it and sending you the screenshots for the same

UmeshDubal_0-1709295070530.png

UmeshDubal_3-1709295125444.png

Its working in my instance
mark helpful if you got your answer

Umesh Dubal
Giga Expert

Hi @Alex319 
I have checked it and sending you the screenshots for the same

UmeshDubal_0-1709295783237.png

 

UmeshDubal_1-1709295783252.png

 

Its working in my instance
mark helpful if you got your answer