How to set default value based on condition

himanshu07
Tera Contributor

I want to set a default value based on the condition and I tried below script in the default filed of dictionary but it didn't work.

If type = group, set the responsibility to 'ABC'(sys_id=1233456667889) of new record only 

javascript:if(current.type("Group"))current.responsibility= "1233456667889";
 
Kindly review and suggest some alternate ideas please.
1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron
function onLoad() {

if(g_form.isNewRecord())
{
var type = g_form.getValue('type'); 
var res = g_form.getValue('responsbility');
if(type == 'group' && res !='')
{
g_form.setValue('responsbility','<sys id that you want to set>'); 
}
}
}

 

Try now.. g_form.isNewRecord() will only allow this onload script to run for new record.

View solution in original post

8 REPLIES 8

Try this:

 

function onLoad() {
var type = g_form.getValue('type'); //Type should be the backend value for type field
var res = g_form.getValue('responsbility');
if(type == group && res !='')
{
g_form.setValue('responsbility','1233456667889'); //Responsibility should be backend value
}

Harsh Vardhan
Giga Patron
function onLoad() {

if(g_form.isNewRecord())
{
var type = g_form.getValue('type'); 
var res = g_form.getValue('responsbility');
if(type == 'group' && res !='')
{
g_form.setValue('responsbility','<sys id that you want to set>'); 
}
}
}

 

Try now.. g_form.isNewRecord() will only allow this onload script to run for new record.

Thanks it worked... instead of using type as 'group', I used type = 'sys_user_group'

Yogish Naik1
Kilo Guru
you can use configure value there you will get calculated option check it and write the same logic