Calling script include from notification (email) script not passing parameter

litchick10
Tera Guru

I have a script includes that works correctly when calling via a catalog item, however, I'm trying to call the same script include via notification script and it does not appear to be passing the parameter, what am I doing wrong. 


Script Includes:

 

 

 

var NotaryInstructions = Class.create();
NotaryInstructions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getNotification: function() {
        var sysIDType = this.getParameter('sysparm_query_sysIDType');
        var parameters = sysIDType.split(',');
        var sysID = parameters[0]; //used to look up records, excluded from this script for brevity
        var n_type = parameters[1]; //used to set content
       var html = '';
 if(n_type == 'instructions'){
        html = '<p>This is the instructions</p>';
      } else { 
       html = '<p>This is the other return value</p>';
     }
  return html;
    },
    type: 'NotaryInstructions'
});

 

 

 


Notification Script:

NOTE: I also tried using GlideAjax but the log showed that GlideAjax was not recognized as a function from the Notification Script. 

 

 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var state = current.u_state;

    var parameters = current.sys_id + ',instructions';
    var helper = new NotaryInstructions();
    var instructions = helper.getInstructions(parameters); 

    email.setSubject("Notary Commission Instructions for the state of " + state.toUpperCase());
    //email.setBody(instructions);
    template.print(instructions);	

})(current, template, email, email_action, event);

 

 

 

 

Notification Outputs

litchick10_0-1718665553873.png

 

 

1 ACCEPTED SOLUTION

We were able to get Developer Support from SNOW and it was the Script includes that needed modified to add an if statement if undefined:

 

var NotaryInstructions = Class.create();
NotaryInstructions.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getNotification: function(sysIDType) {
        if (typeof sysIDType === 'undefined') {
            sysIDType = this.getParameter('sysparm_query_sysIDType');
        }
        var sysID = parameters[0]; //used to look up records, excluded from this script for brevity
        var n_type = parameters[1]; //used to set content
       var html = '';
 if(n_type == 'instructions'){
        html = '<p>This is the instructions</p>';
      } else { 
       html = '<p>This is the other return value</p>';
     }
  return html;
    },

	type: 'NotaryInstructions'
});

 

Also a couple of minor edits on the notification script:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    //Get state
    var state = current.u_state;

    var sysIDType = current.sys_id + ',instructions';
    var helper = new NotaryInstructions();
    var instructions = helper.getNotification(sysIDType);
    email.setSubject("Notary Commission Instructions for the state of " + state.toUpperCase());
    email.setBody(instructions);

})(current, template, email, email_action, event);

View solution in original post

6 REPLIES 6

Kris Moncada
Tera Guru

Hi @litchick10 ,

 

The issue, most likely, is that your Script Include is client callable; of which should be unchecked if you would like to call the Script Include on a server side mail script.

 

To test this this out, create a new Script Include with "client callable" unchecked. Then define a function that returns a test string. Call the new Script Include in the mail script,  

 

If everything is working fine, then it's a issue with Script Include being callable.

 

Hope this helps.

Amit Verma
Kilo Patron
Kilo Patron

Hi @litchick10 

 

I could see you are not calling the right function in your Script Include. Your Script Include function is getNotification() and you are calling getInstructions(). Refer below updated Script Include and Email Script and give it a try :

 

var NotaryInstructions = Class.create();
NotaryInstructions.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getNotification: function(sysIDType) {
        var parameters = sysIDType.split(',');
        var sysID = parameters[0]; //used to look up records, excluded from this script for brevity
        var n_type = parameters[1]; //used to set content
       var html = '';
 if(n_type == 'instructions'){
        html = '<p>This is the instructions</p>';
      } else { 
       html = '<p>This is the other return value</p>';
     }
  return html;
    },

	type: 'NotaryInstructions'
});

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {
    var state = current.u_state;

    var sysIDType = current.sys_id + ',instructions';
    var helper = new NotaryInstructions();
    var instructions = helper.getNotification(sysIDType); 
    email.setSubject("Notary Commission Instructions for the state of " + state.toUpperCase());
    email.setBody(instructions);
    //template.print(instructions);	

})(current, template, email, email_action, event);

 

AmitVerma_0-1718771107300.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

I'm still getting undefined. I tried checking/unchecking the client callable on the script includes.  So we don't have any confusion, here is my current script includes:

litchick10_0-1718899583607.png

Here is my updated Notification script:

litchick10_3-1718900345165.png

 

Here is my Notification preview:

litchick10_2-1718899845078.png

I added a log to the script include and both client callable and non-client callable returned this:

litchick10_4-1718900511831.png

 

 

 

Since your script include has client callable elements (i.e. this.getParameter('')), I would recommend leaving the client callable checked

 

Line 10 of your notification script is passing a value to the function getNotification(), but no arguments are defined. 

 

If you are planning on using the script include for both client side and server side, you'll need to do something like the following:

getNotification: function(sysIDType_str) {

		var sysIDType = this.getParameter('sysparm_query_sysIDType')? this.getParameter('sysparm_query_sysIDType') : sysIDType_str; 
		//....
    }

 

Also I would highly not recommend not toggling the client callable check box for an already established Script Include.  I have instances where Script includes were not recognized as client callable, though the checkbox was ticked.  I chalked it up to a ServiceNow quirk I had to get used to.

 

Hope this helps.