How to convert field value from string to integer

Yogeshwari
Tera Contributor

I am trying to write a fix script for copy data from a string field to interger field, can you please help with the function which is used to convert string to integer

3 REPLIES 3

Community Alums
Not applicable

Hello @Yogeshwari ,

You can use the parseInt(""); function to have a string return an integer.

Thanks!

can u give me an example!!

 

Sai Shravan
Mega Sage

Hi @Yogeshwari ,

you can use the parseInt() function to convert a string to an integer in JavaScript. Here's an example of how you can use the parseInt() function in your fix script to copy data from a string field to an integer field:

var current = new GlideRecord('table_name'); // Get the current record
current.get('sys_id', 'current_record_sys_id');
var sourceValue = current.getValue('source_field'); // Get the string value from the source field
var intValue = parseInt(sourceValue); // Convert the string value to an integer using parseInt()
current.setValue('target_field', intValue);/ / Set the integer value in the target field
current.update(); // Update the record

Note that if the source field value cannot be converted to an integer, the parseInt() function will return NaN (Not a Number).

 

Regards,

Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you