We’re creating a method that handles transactions (invoices, po’s, transfers). I’m using the get element function to help the method determine what kind of transaction it is … so I’m using a switch function.
When i step through the method, the transCreate var has the value and if I evaluate one of my expressions… it looks good, but the switch always jumps to the default.
Am I such a noob that I can’t tell what’s happening?
[note, i’ve tried both the utils pattern count and the index.of… and get the same behavior for both.
var transCreate = application.getMethodTriggerElementName()
var x = ""
switch (transCreate)
{
case utils.stringPatternCount(transCreate,'invoice') >= 0: x = 'I'
break;
case transCreate.indexOf('po') >= 0: x = 'P'
break;
case transCreate.indexOf('adjustment') >= 0: x = 'A'
break;
case transCreate.indexOf('transfer') >= 0: x = 'T'
break;
default: x = 'E';
}
//
var transType = x
To simplify things still further why don’t you alter the actual trigger element name to include the identifying character to extract as this means that you can get rid of the Switch function or If/ElseIf statement completely and just use a substring extract function
You obviously have a complex element name to begin with in order that you use a pattern count function to test if the substring exists.
So starting with a potential element name of, say, ‘invoice_xxxxxx’ you alter this to ‘I_invoice_xxxxx’ and do the same for the other element types with their 1char identifiers and then use the following code to extract it:
var transCreate = application.getMethodTriggerElementName();
var transType = transCreate.substr(0 , 1);