How to convert field value from string to integer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 12:13 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2023 02:21 AM
Hello @Yogeshwari ,
You can use the parseInt(""); function to have a string return an integer.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2024 02:26 AM
can u give me an example!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2023 06:42 AM
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
Shravan
Please mark this as helpful and correct answer, if this helps you