- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 03:16 AM
Can the field type be changed in the manually created field on the incident form? I have a field "Value" with its field type set to string and i filled data in it too, but I want to change it to an integer. I mistakenly put the field type as a string.
or tell me can we find the MAX value of that same field 'VALUE', with the field type is a string
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 03:54 AM - edited 10-24-2024 03:55 AM
I tried this on my pdi and it works
I tried with reassignment_count field
var count=new GlideAggregate('incident');
//count.addEncodedQuery('manufacturer=b7e9e843c0a80169009a5a485bb2a2b5');
count.addAggregate('MAX','u_value');
count.setGroup(false);
count.query();
while(count.next()){
gs.print(count.getAggregate('MAX','u_value'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 03:54 AM - edited 10-24-2024 03:55 AM
I tried this on my pdi and it works
I tried with reassignment_count field
var count=new GlideAggregate('incident');
//count.addEncodedQuery('manufacturer=b7e9e843c0a80169009a5a485bb2a2b5');
count.addAggregate('MAX','u_value');
count.setGroup(false);
count.query();
while(count.next()){
gs.print(count.getAggregate('MAX','u_value'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 04:55 AM
Hi Anurag,
thanks for your replies.
I created a new field and made it field type an integer. (instead of string)
and i just added .setGroup(false);
as you said
and its workss!!
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 03:53 AM - edited 10-24-2024 03:56 AM
Hello @rohitshrikhande
Since the value is stored as a string, firstly it has to be converted to number. The below code can be run in server side scripting like business rules, script includes.
var maxValue = 0;
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_valueISNOTEMPTY'); // Ensure value field is not empty
gr.query();
//gs.log(gr.getRowCount());
while (gr.next()) {
var numValue = parseFloat(gr.getValue('u_value')); // Convert string to a number
if (!isNaN(numValue) && numValue > maxValue) {
maxValue = numValue;
}
}
gs.log('Maximum numeric value in the value field: ' + maxValue);
Preview of result:
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar