Calling Script Include from client script include is not working for me

krishna0505
Tera Contributor

My Client Script Include : 

my client script include : 

function include({imports}) {

    return shareBulKReports;

    function shareBulKReports(query){

        var objGA = new GlideAjax("global.shareReportsWithGroups");
        objGA.addParam('sysparm_name', "shareReports");
        objGA.addParam('sysparm_query',query.toString());
        objGA.getXML(validateResponse);

        function validateResponse(response){
            var result = response.responseXML.documentElement.getAttribute("answer");
        }
    }

}



var shareReportsWithGroups = Class.create();
shareReportsWithGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	shareReports : function(){
		
        var query = this.getParameter("sysparm_query");
		gs.info(query,"venkat");
		gs.log(query,"venkat");
        this.fetchGroups(query);
    },

    fetchGroups : function(query){
        var groupsGr = new GlideRecord("sys_user_group");
        groupsGr.addEncodedQuery(query);
        groupsGr.query();

        var groupSysIds = [];
        while(groupsGr.next()){
            groupSysIds.push(groupsGr.getUniqueValue());
        }

        this.shareReportstoGroups(groupSysIds);
    },

    shareReportstoGroups : function(groups){
        gs.info(groups, "venkat");
    },

    type: 'shareReportsWithGroups'
});

 

My client script include is working fine, I have logged to check it. 

Regards,
Venkat

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@krishna0505 

why are you separating the functions?

why not call the single function and do that?

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

    fetchGroups: function(query) {
        var query = this.getParameter('sysparm_user_sys_id') || query;
        var groupsGr = new GlideRecord("sys_user_group");
        groupsGr.addEncodedQuery(query);
        groupsGr.query();
        var groupSysIds = [];
        while (groupsGr.next()) {
            groupSysIds.push(groupsGr.getUniqueValue());
        }

        return groupSysIds.toString();
    },

    shareReportstoGroups: function(groups) {
        gs.info(groups, "venkat");
    },

    type: 'shareReportsWithGroups'
});

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

krishna0505
Tera Contributor

I don't think it is calling script include itself firstly, I have kept log statements at the start of the function. I couldn't see any logs. 

is there any reason do you think why it is not calling script include?

Regards,
Venkat

@krishna0505 

please share the complete client side code which you are using

both client code and script include are in same scope?

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

krishna0505
Tera Contributor

I have already share in question post. Sharing here it again. 

Note: My client script is client script include which generally used in UI Builder Client scripts

my client script include : 

function include({imports}) {

    return shareBulKReports;

    function shareBulKReports(query){

        var objGA = new GlideAjax("global.shareReportsWithGroups");
        objGA.addParam('sysparm_name', "shareReports");
        objGA.addParam('sysparm_query',query.toString());
        objGA.getXML(validateResponse);

        function validateResponse(response){
            var result = response.responseXML.documentElement.getAttribute("answer");
        }
    }

}

 
and this is my script include : 

var shareReportsWithGroups = Class.create();
shareReportsWithGroups.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	shareReports : function(){
		
        var query = this.getParameter("sysparm_query");
		gs.info(query,"venkat");
		gs.log(query,"venkat");
        this.fetchGroups(query);
    },

    fetchGroups : function(query){
        var groupsGr = new GlideRecord("sys_user_group");
        groupsGr.addEncodedQuery(query);
        groupsGr.query();

        var groupSysIds = [];
        while(groupsGr.next()){
            groupSysIds.push(groupsGr.getUniqueValue());
        }

        this.shareReportstoGroups(groupSysIds);
    },

    shareReportstoGroups : function(groups){
        gs.info(groups, "venkat");
    },

    type: 'shareReportsWithGroups'
});

 

and they are in same application scope.