default value in choice list using 'javascript'

ckjbeos
Mega Expert

Hi,

in my incident Forms i try to set the value of 'contact_type' field (field is a choice list)

using javascipt into default value, i want to set the value for user have a specific role

in first time i just try with role 'itil'

i write this :

javascript:if (gs.hasRole("itil")) {phone} else {portail};

but not work

later i will create a special role 'hotliner_role' and use this role.

regards,

Cedric

1 ACCEPTED SOLUTION

Hi Tomasi,



finally with you're help and sample code finded into System>Dictionary



i write this :


javascript:(function() {if (gs.hasRole('itil')) return 'phone'; else return 'portail';})()



and IT'S WORK YES !!!



great thanks for you're help


Best regards,


Cedric


View solution in original post

15 REPLIES 15

Danny Mortensen
Tera Contributor

Hi, 

I know it's an old post now, but I think it was just your syntax that was wrong. When you placed your code in the function that worked you had the syntax correct. It should have worked without the self executing function.

Your semi-collons were the problem I think.

This: javascript:if (gs.hasRole("itil")) {phone} else {portail};

Should be: javascript: if (gs.hasRole('itil')) return 'phone'; else return 'portail';

OR

javascript:if (gs.hasRole("itil")) {phone;} else {portail;}

P.S. Not tested