Script include not working on public form

Kenton Dover
Mega Guru

Hi all,

I have a script include that is being called from a client script that logs a message so that we know when a public user that is not logged in accesses a form. It logs the message fine when I am logged in however when in an incognito window it does not log the message. The rest of the form functions just fine in this public state. 

 

Here is the client script: 

var log = new GlideAjax("scope.log_message");

    log.addParam('sysparm_name', 'log');
    log.addParam('sysparm_msg', message);
    log.getXML(callback);
    function callback(response) {
		
    }

Here is the script include:

var log_message = Class.create();
log_message.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    log: function() {
        gs.info(this.getParameter("sysparm_msg"));
    },
    type: 'log_message'


});

 

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

For a public page you will need to set the privacy on your script include to be public as well, otherwise it will not execute for non-logged in users. 

https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/concep...

Privacy settings

The privacy setting for a client-callable script-include can be public or private. Most client-callable script-includes are marked private by default.

The private privacy-setting means that guests who access public pages cannot access the client-callable script-include. A private script cannot be executed by a non-logged-in user.

A public privacy-setting means that the client script can be executed by non-logged-in users that create an appropriate HTTP request. This can create a security problem if the client script provides confidential information.

Change privacy on a single client callable script include

Change the privacy setting for a single client-callable script include by adding the isPublic() function.

The isPublic() setting takes precedence over the glide.script.ccsi.ispublic property. For example, if the property is set to false, making all client-callable script-includes private, and a script sets isPublic() to true, the script is public.

To change the privacy for a single client-callable script include, add the following method to the script include:

  isPublic:function(){return[true/false];},

Example

Make the NewInclude client script private.
var NewInclude =Class.create();
 
NewInclude.prototype={
   initialize:function(){},
 
   myFunction:function(){//Put function code here},
   isPublic:function(){return false;},
 
   type:'NewInclude'};

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the GlideFast Consulting team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

2 REPLIES 2

Michael Jones -
Giga Sage

For a public page you will need to set the privacy on your script include to be public as well, otherwise it will not execute for non-logged in users. 

https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/concep...

Privacy settings

The privacy setting for a client-callable script-include can be public or private. Most client-callable script-includes are marked private by default.

The private privacy-setting means that guests who access public pages cannot access the client-callable script-include. A private script cannot be executed by a non-logged-in user.

A public privacy-setting means that the client script can be executed by non-logged-in users that create an appropriate HTTP request. This can create a security problem if the client script provides confidential information.

Change privacy on a single client callable script include

Change the privacy setting for a single client-callable script include by adding the isPublic() function.

The isPublic() setting takes precedence over the glide.script.ccsi.ispublic property. For example, if the property is set to false, making all client-callable script-includes private, and a script sets isPublic() to true, the script is public.

To change the privacy for a single client-callable script include, add the following method to the script include:

  isPublic:function(){return[true/false];},

Example

Make the NewInclude client script private.
var NewInclude =Class.create();
 
NewInclude.prototype={
   initialize:function(){},
 
   myFunction:function(){//Put function code here},
   isPublic:function(){return false;},
 
   type:'NewInclude'};

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the GlideFast Consulting team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Thank you this was exactly what I needed