Flow variable problème

hi everyone
i have a problem in the function node
here i don't why when i run the code work well but here the code return me msg.topic=" no ............ " and msg4.enabled = true its impossible i don't now the problem help me

//let fin_intab = flow.get("article_mp");
let  fin_intab =[{ "code": "01", "libelle": "ÐÑÉ", "qteart": -3804, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2022-10-05T20:00:00.000Z" }, 
{ "code": "02", "libelle": "ÕæíÇ", "qteart": -1334, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2022-10-05T20:00:00.000Z" }, 
{ "code": "03", "libelle": "ÔÚíÑ", "qteart": -1559, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2022-10-05T20:00:00.000Z" }, 
{ "code": "06", "libelle": "ÒíÊ", "qteart": -30, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2022-10-05T20:00:00.000Z" }, 
{ "code": "001", "libelle": "CMV", "qteart": -63.4, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "1", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2022-10-05T20:00:00.000Z" },
{ "code": "002", "libelle": "ÝæÓÝÇØ", "qteart": -570, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "1", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": "01", "datemaj": "2022-10-05T20:00:00.000Z" }, 
{ "code": "0009", "libelle": "äÎÇáÉ", "qteart": -1020.2, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "1", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2022-10-05T20:00:00.000Z" }, 
{ "code": "20", "libelle": " Ýæá ÓæÏÇäí", "qteart": -73, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 5, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2023-03-23T20:00:00.000Z" },
 { "code": "21", "libelle": "ÈÑíãßÓ ÃÛäÇã", "qteart": -179.7, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "1", "recepfosse": "1", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2023-03-23T20:00:00.000Z" },
 { "code": "05454", "libelle": "hjkghjk", "qteart": 0, "tolerance": 0, "tolermax": 0, "densite": 0, "poidsunit": 0, "durevie": 0, "nbrtourbroy": 0, "avec_cb": "0", "autorise": "0", "recepfosse": "0", "conditionnement": "", "codebarre": "", "prixnet": 0, "poidsmin": 0, "poidsmax": 0, "broyage": "0", "codetrs": "", "libtrs": "", "aveclot": "0", "artcmv": "0", "arthuile": "0", "ajoutman": "0", "service": "0", "exceft": "0", "chute": 0, "pvitesse": 0, "gvitesse": 0, "beine": "0", "capbeine": 0, "arteau": "0", "artsurfac": "0", "nbjalerte": 0, "nbjalerte1": 0, "qtemin": 0, "usera": "01", "userm": null, "datemaj": "2023-09-30T20:00:00.000Z" }];



//let choix_matiere_a_modifeaa = flow.get("choix_matiere_a_modifeaa");
//let choix_matiere_modife = flow.get("choix_matiere_modife");

let choix_matiere_modife ={"code":"06","libelle":"CMV","qteart":-30,"tolerance":0,"tolermax":0,"densite":0,"poidsunit":0,"durevie":0,"nbrtourbroy":0,"avec_cb":"0","autorise":"1","recepfosse":"1","conditionnement":"","codebarre":"","prixnet":0,"poidsmin":0,"poidsmax":0,"broyage":"0","codetrs":"","libtrs":"","aveclot":"0","artcmv":"0","arthuile":"0","ajoutman":"0","service":"0","exceft":"0","chute":0,"pvitesse":0,"gvitesse":0,"beine":"0","capbeine":0,"arteau":"0","artsurfac":"0","nbjalerte":0,"nbjalerte1":0,"qtemin":0,"usera":"01","userm":null,"datemaj":"2022-10-05T20:00:00.000Z","id":3};

let choix_matiere_a_modifeaa  = {"code":"06","libelle":"ÒíÊ","qteart":-30,"tolerance":0,"tolermax":0,"densite":0,"poidsunit":0,"durevie":0,"nbrtourbroy":0,"avec_cb":"0","autorise":"1","recepfosse":"1","conditionnement":"","codebarre":"","prixnet":0,"poidsmin":0,"poidsmax":0,"broyage":"0","codetrs":"","libtrs":"","aveclot":"0","artcmv":"0","arthuile":"0","ajoutman":"0","service":"0","exceft":"0","chute":0,"pvitesse":0,"gvitesse":0,"beine":"0","capbeine":0,"arteau":"0","artsurfac":"0","nbjalerte":0,"nbjalerte1":0,"qtemin":0,"usera":"01","userm":null,"datemaj":"2022-10-05T20:00:00.000Z","id":3}
var x=0;
const msg4 = { "enabled": false };

if (JSON.stringify(choix_matiere_a_modifeaa) != JSON.stringify(choix_matiere_modife)){
    var __FOUND = fin_intab.find(function (post, index) {

        


         if (post.libelle == choix_matiere_modife.libelle ) {
            msg.topic = "  no ............  " ;
            
            x = 2;
            return true;
        } else { 
             msg.topic = "  enregestrement en cours";
            x = 4;
            msg4.enabled = true;
            
            }
    })
    
    
};


return [msg, msg4];

We can only speculate since there is not enough info.

If you want further help, please supply sample data for article_mp, choix_matiere_a_modifeaa and choix_matiere_modife.

1 Like

Also, do yourself a favour. the JSON.stringify and JSON.parse functions are notoriously brittle. Always surround their use with try/catch blocks to prevent unexpected nasty errors.

1 Like

the problem here is that entre in the first if statement and if true must don't look to the else statement but here no

Add node.warn() statements to your function to work out what is going on.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.