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

SaiRaviKiran Ak
Giga Guru

You can achieve this using OnLoad Client script.

 

Script should be like below:

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

}

 

 

If a record has responsibility as 'xyz' and user open the form. The above client script will set the value of responsibility to 'abc'

Whenever you open the form it will check if type is group or not.

If it is group then it will set the responsibility to mentioned sys_id.

 

Is this not your requirement ?

No this is not my requirement.... 

 

Responsibility field has numerous values but only when creating the NEW record, it should by default populate the "ABC" in responsibility field