- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 01:50 AM
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'
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2022 01:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 02:25 AM
Hi,
BR script looks fine
Script Include
1) alert() won't work -> remove that
2) you cannot use Ajax inside script include
What exactly you want to perform?
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2022 01:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2022 02:37 AM
Hello Martina,
Your script include GLSRecuperaClienteTOP has issue like you have used ga.addParam with is used for GlideAjax() call to pass the parameter from client script to server script. It seems have little less knowledge about Client script and Server side scripting and hence you used the code in Script include that was actually supposed to be used in Client side.
Could you please remove your makeCall() function script and replace that with the below script and check if you are able to achieve your requirement:
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 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();
}
gs.info('PM20220627 post chiamata makeCall ');
},
type: 'GLSRecuperaClienteTOP'
});
If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. This will help others with similar issue to find the correct answer.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022 11:38 PM
Hello
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
Thanks