The CreatorCon Call for Content is officially open! Get started here.

"undefined" string

terp
Giga Contributor

On my record producer, the string "undefined" appears upon opening the form. It is not defined as a default value, the "type" is a multi line text and is mapped to the field on the table.   Can anyone   suggest why this string is there and how get rid of it?

find_real_file.png

1 ACCEPTED SOLUTION

Hi Eric,



Try the following...


if (shipping_special_instructions && shipping_special_instructions != ''){


        g_form.setValue('u_shipping_special_instructions',shipping_special_instructions);


}



Thanks,


Berny


View solution in original post

7 REPLIES 7

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Does the variable have a default value defined? If so, what is it? If not, do you have a client script populating the default value?


bernyalvarado
Mega Sage

Hi Eric,



Just make sure that whenever your're assigning a value to this field you first validate that the variable is valid and does contain a value on it.



For instance, something like the following:



function onLoad() {


 


    var incredible;


    if (incredible && incredible != ''){


      g_form.setValue('myVariable', incredible);


    }


}



if i miss adding the first validation to check if the variable is initialized, then I will get the undefined value on the field:



function onLoad()


    var incredible;


    if (incredible != ''){


      g_form.setValue('myVariable', incredible); // myVariable will be set to Undefined since the variable incredible was never initialized


    }


}



I hope this helps!



Thanks,


Berny


terp
Giga Contributor

Thanks for the suggestions and pointing me one direction.   I checked the default values on the record producer and table,   nothing listed there.   Also checked the client scripts.   There is only 1 client script with that field name listed and that is pulling values from another table on the condition of a UI action.



In this case, I am opening the record producer form, and the form should be blank (including this field) and "undefined" is in the field. If this makes a difference, in the table, the field is a string with a size limit of 500 and in it is mapped in the record producer as a multiple line text.   When the record producer form is opened this field should be empty.



This was the only client script that I have with the field.   Any additional thoughts would be appreciated and Happy New Years to everyone.



function onChange() {


                            //control, oldValue, newValue, isLoading    


                            var inventory = g_form.getReference('u_inventory_search');


var shipping_special_instructions = inventory.u_shipping_special_instructions;



g_form.setValue('u_shipping_special_instructions',shipping_special_instructions);







find_real_file.png


Hi Eric,



Try the following...


if (shipping_special_instructions && shipping_special_instructions != ''){


        g_form.setValue('u_shipping_special_instructions',shipping_special_instructions);


}



Thanks,


Berny