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

Chuck Tomasi
Tera Patron

If you want to do this in a client script you could use an onLoad client script something like this. Note, this is untested...



if (g_user.hasRole('itil')) {


        g_form.setValue('contact_type', 'phone');


} else {


        g_form.setValue('contact_type', 'portal');


}



Docs: Client Scripts


Docs: GlideForm


Developer: Client Scripting Technical Best Practices Overview


Hi Tomasi,



i know clientscript onLoad, but i think i t's more good to do this into default value, because i just need to set this value for new incident not existing


that's why i prefer to set it into the default field value



Regards,


Cedric


Hi Cedric,



You would then do this from the dictionary entry for that field with something similar to this:



javascript:if (gs.hasRole('itil')) current.contact_type = 'phone';



Reference: Specify a default field value


Hi Tomasi,



YES ! it's work, you're code work nice


but ! how can i set 'portail' if the user have not 'itil' role ?



Regards,


Cedric