Painless scripted field with nested IF statment

I have these two working scripted fields:

def M3 = doc['obj'].value.splitOnToken('_'); return M3.length >= 4 ? M3[3] : null;

def M2 = doc['obj'].value.splitOnToken('_'); return M2.length >= 4 ? M2[2] : null;

that I would like to merge in an unique scripted field using a nested IF statement following these rules:

if(doc['label'].value == 'MLD42')

return (M3):
doc['obj'].value.splitOnToken('_'); return LU2.length >= 4 ? LU2[2] : null;

else return(M2):
doc['obj'].value.splitOnToken('_'); return LU3.length >= 4 ? LU3[3] : null;

I still can't do it correctly, please help me with the correct syntax
Thank you

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