set value using client script

polodre2
Tera Contributor

I have a script that sets the value from another field on the form but it seems to be adding extra characters to the end.

The client script is read the Parent Agreement number and setting it in the field information:

 

polodre2_0-1706886533104.png

polodre2_1-1706886629941.png

The highlighted field should be showing the exact value from the Parent Agreement field but it adds -J001.

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @polodre2 

Please give a try to the script below and see how it works for you.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var choiceoption = g_form.getValue('u_art_4_2_1_dp1_fin_obl');
    var getNameValue = g_form.getDisplayValue('u_parent_agreement');

    if (choiceoption == 'No Cost Option') {
        var message = 'ARL CRADA + (' + getNameValue + ') Article 5.2.1, "No Cost Option" has been chosen for technical efforts under this JWS';
        g_form.showFieldMsg('u_art_4_2_1_dp1_fin_obl', message, 'info');
        g_form.addInfoMessage(message);
    } else if (choiceoption == 'Payment to ARL Option') {
        var message = 'ARL CRADA + (' + getNameValue + ') Article 5.2.2, "Payment to ARL Option" has been chosen for technical efforts under this JWS';
        g_form.showFieldMsg('u_art_4_2_1_dp1_fin_obl', message, 'info');
        g_form.addInfoMessage(message);
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket

View solution in original post

8 REPLIES 8

Sagar Pagar
Tera Patron

Hi @polodre2,

 

I think it is taking extra value as you are using getDisplayValue('field_name'). Can you try it with getValue('field_name') method?

 

var getNameValue = g_form.getValue('field_name');

 

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

I used getDisplayValue because getValue was returning the sysID

Hello Polodre2,

 

What is the variable type for Parent Agreement

Parent Agreement is a reference field

polodre2_0-1706897797168.png