Onload catalog client script not working

gtgauravtya
Tera Contributor

I have created a Onload Catalog client script retrieve the first date of current month and below is the code -

script include script - 

    getEffectiveDate: function() {
        var currentDate = new GlideDateTime();
        // Set the day of the month to 1
        currentDate.setDayOfMonthUTC(1);
        var firstDayOfMonth = currentDate.getLocalDate();

        return firstDayOfMonth;
    }
 
 ------------------------------------
 
Catalog client script -
 
function onLoad() {
    var getDate = new GlideAjax('script_include_name');
    getDate.addParam('sysparm_name', 'getEffectiveDate');
    getDate.getXML(getDateTime);

    function getDateTime(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('u_effective_date', answer);
        g_form.setMandatory('u_effective_date', false);
        g_form.setReadOnly('u_effective_date', true);
    }
}
----------------------------
This is working fine for most of the users but not working for couple of users.
I tested with 2 users having same role and member of same groups , but it working for 1 and not for other.
Please suggest possible ways to analyze this issue

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@gtgauravtya 

script should not have any dependency with the user who is logged in

Is the user for whom it's not working an external user?

Also check the ACL which is added on Client callable script include, what role is given there.

May be the other user doesn't satisfy the ACL role and hence Ajax call is not happening

if the user is external then add this function in your script include so that external user is able to make GlideAjax call

in your client callable script include add the isPublic function along with your existing functions

isPublic: function(){
return true;
},

check this link

Privacy on client-callable script includes (instance security hardening) 

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

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@gtgauravtya 

script should not have any dependency with the user who is logged in

Is the user for whom it's not working an external user?

Also check the ACL which is added on Client callable script include, what role is given there.

May be the other user doesn't satisfy the ACL role and hence Ajax call is not happening

if the user is external then add this function in your script include so that external user is able to make GlideAjax call

in your client callable script include add the isPublic function along with your existing functions

isPublic: function(){
return true;
},

check this link

Privacy on client-callable script includes (instance security hardening) 

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

Hi Ankur , the Script include's ACL was having a role which was missed in user profile. Thanks for the quick help

@gtgauravtya 

Glad to help.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@gtgauravtya 

what's your business requirement?

do you want 1st day of current month and set that in date variable ?

if yes then use this default value of that variable and make it readonly

javascript: var currentDate = new GlideDateTime();
        currentDate.setDayOfMonthUTC(1);
        var firstDayOfMonth = currentDate.getLocalDate();
        firstDayOfMonth;

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