Business rule with script include not work

Martina9
Kilo Expert

HIi all,

The aim of this br was to set a true/false field to true if it matched a record through an integration but it doesn't work, could you help me?

Here is BR and Script include

 

Business rule:

condition --> after update

(function executeRule(current, previous /*null when async*/ ) {

     
    gs.info('PM20220907 entro nella business');
    
    var idSpedizione = current.getValue("u_numero_di_spedizione"); //get the value of numero di spediione field
    var idSegnalazSedeSede = current.getValue("sys_id"); //get the value of numero di spediione field
    gs.info('PM20220907 idSpedizione ' + idSpedizione + 'idSegnalazSedeSede' + idSegnalazSedeSede);
    
    var recuperoReclamo = new global.GLSRecuperaClienteTOP();
    recuperoReclamo.makeCall(idSpedizione, idSegnalazSedeSede);


})(current, previous);


Script include (client callable):

var GLSRecuperaClienteTOP = Class.create();
GLSRecuperaClienteTOP.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    makeCall: function(idSpedizione, idSegnalazSedeSede) {

        gs.info('PM20220627 entro GLSRecuperaClienteTOP idSpedizione  ' + idSpedizione + 'idSegnalazSedeSede ' + idSegnalazSedeSede);

        var tipo = "S"; //for numero_di_spedizione the tipo is always "S"

        //make a call to a script include, which in turn will make a call to DBServ.
        var ga = new GLSDBServIntegrazione(); //name of the script include which is called
        //var a = ga.makeCallWithParameters(idSpedizione, tipo);
        ga.addParam("sysparm_name", "makeCall"); //name of a function that is called inside the sxript inxlude
        //pass the id and the tipo to the needed parameters of the script include
        ga.addParam("receivedID", idSpedizione);
        ga.addParam("receivedTipo", tipo);
        ga.getXML(callbackFunction); //call the script include


        gs.info('PM20220627 post chiamata makeCall ');

        // ga.getXML(callbackFunction); //call the script include

        function callbackFunction(response) {

            gs.info('PM20220627 callbackFunction ' + response);
            //receive a response from the script include, a JSON string is returned
            var answer = response.responseXML.documentElement.getAttribute("answer");
            var answ = JSON.parse(answer);
            var obj = answ.wsResonse; //get an array
            var wsResp = obj[0]; //get the first array element

            var errore = wsResp.errore;
            var wsMsg = answ.wsMessage;
            var reclamoTop = wsResp.reclamoTop;

            if (errore == "") {
                //If there is no error, numero di spedizione exists either on custom table or on DBServ
                //form fields are populated 
                if (reclamoTop) {
                    var sedeSede = new GlideRecord("u_gls_comunicazione_sede_sede");
                    sedeSede.addQuery('sys_id', idSegnalazSedeSede);
                    sedeSede.query();
                    if (sedeSede.next()) {
                        gs.info('PM20220627 faccio');
                        sedeSede.setValue("u_reclamo_top", true);
                        sedeSede.update();
                    }
                }


            } else {
                gs.info('PM20220627 errore ' + errore);
                gs.error(errore);
                alert(errore);
            }

        }
    },

    type: 'GLSRecuperaClienteTOP'
});
1 ACCEPTED SOLUTION

Thank you for your intervention, I applied your suggestions but they did not solve the problem.

I managed by modifying the called include script and calling a function from the same script by putting this. before the function name

View solution in original post

5 REPLIES 5

Thank you for your intervention, I applied your suggestions but they did not solve the problem.

I managed by modifying the called include script and calling a function from the same script by putting this. before the function name