jeudi 19 août 2021

ServiceNow Script Include - return BOTH these messages in one condition - If/else statement

I've got this If/Else, and are facing an issue im not sure how to resolve. (CODE BELOW IS JUST A EXAMPLE, NOT THE REAL CODE - Javascript)


                if (grDist.testUnit == testUnit && grDist.testHouse == testHouse) {
                            var msgOne=  variable1 + variable2; //adding the data i want to return
                            return msgOne;
                }else{
                    if(grDist.divS == divS) {
                        var msgTwo= var1 + var2 // same here but different data to return
                        return msgTwo;
                    }
                }



There is a scenario where i want to return BOTH these two different messages, which goes to a Client script where i display the information in a "g_form.showFieldMsg".

So my question is: How can I use the If/Else statement to make a condition that will give me both msgOne and msgTwo. Feels like it can be done with just the rigt condition. They basically do the same thing just with another message and 1 more line of data.

So far i tried it like this:


 if (grDist.testUnit == testUnit && grDist.testHouse == testHouse && grDist.divS.....){

   
}

But that wont do it, it just gives me msgOne, nothing else.

Any suggestions? If you need more information just tell me, hard to describe without giving out sensitive info.

Aucun commentaire:

Enregistrer un commentaire