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

Hey Cedric,



You could try my code and check




post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


divya mishra
Tera Guru

Hey Cedric,



Write an onload client script :


then use this code:


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


g_form.setValue("field","value");




post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


divya mishra
Tera Guru

Hey Cedric,



Wrote this on incident form. It worked


Sample:


function onLoad() {


    //Type appropriate comment here, and begin script below


    if(g_user.hasRole("admin"));


g_form.setValue("urgency",'2');


alert("Changed urgency");



}



post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


Hi Mishra,



i know i can ue onLoad clientscript, but i prefer set the value into default value field, because it's only needed when creating incident.


On load is called always you load the forms and is more complicated i think because need more test.


defalut value of a field is set only on creation of object that's why i think it's more good.



Regards,


Cedric


Ok Cedric,



I have another solution then


Create a BR:


1.JPG2.JPG