Benefit Plan table - Set Category Soft when a new NonMonetary Plan gets created

PaulaaO
Mega Sage

Hi Community,

I would like to know what is the best approach to set in benefit_plan table, Category to Soft when the Benefit type is Non-monetary benefits.

I managed to create onChange Client script to map Benefit Type to Category, however I still have the case where if I create a new record from the Non-monetary Benefit Plans related list from project form, because Category field has hard as the default value, even if the form opens on Benefit type = Non monetary, the Category remains Hard and it allows the user to create such records which is not the behaviour we want.

I have seen on other posts that either a Business Rule or an onLoad Client Script would make this happen - which one is the recommended approach? I only had a go at an OnLoad Client script, but did not manage to make it work

 

function onLoad() {
    //if a new Non monetary benefit plan gets created the category field is set on Soft

    if (g_form.isNewRecord()); {
        var benefitType = g_form.getValue('benefit_type');
        if (benefitType == 'non-monetary') {
            g_form.setValue('category', "soft");
        }
    }
}

Any help would be much appreciated.

Thank you,

Paula

 

P.S. I made Category field ReadOnly so the user cannot change it manually, hence the reason I need to make the above work.

 

P.S.2:  I updated the onChange Client Script and seems this works - as I'm quite a newbie in development would appreciate if you could advise whether I missed anything and if the below is correct:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === 'non_monetary') {
		g_form.setValue('category', "soft");
	}
        

    //value of Category changes based on the choice selected from Benefit Type field
    if (newValue == 'monetary')
        g_form.setValue('category', "hard");
    if (newValue == 'non_monetary')
        g_form.setValue('category', "soft");

}
1 ACCEPTED SOLUTION

Tapish Sharma1
Kilo Sage

Hi Paula,

You can use OnChange client script to achieve this requirement. You can go ahead with your second script.

 

Kindly Mark helpful/Correct is this answered your query

View solution in original post

2 REPLIES 2

Tapish Sharma1
Kilo Sage

Hi Paula,

You can use OnChange client script to achieve this requirement. You can go ahead with your second script.

 

Kindly Mark helpful/Correct is this answered your query

PaulaaO
Mega Sage

For whomever might be interested for a similar user case, please see below my final script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    //when a new form is opened via the project related list: Non-monetary benefit plans -> Category to be set to Soft; 
    if (isLoading || newValue === 'non_monetary') {
        g_form.setValue('category', "soft");
    }

    //when Benefit type changes to Monetary, Category value is set to Hard
    if (newValue == 'monetary')
        g_form.setValue('category', "hard");
}