Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

change type of field

rohitshrikhande
Tera Contributor

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 

1 ACCEPTED SOLUTION

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'));
}

 

-Anurag

View solution in original post

7 REPLIES 7

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'));
}

 

-Anurag

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!!

rohitshrikhande_0-1729770895288.png

Thanks. 

Juhi Poddar
Kilo Patron
Kilo Patron

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:

JuhiPoddar_0-1729767121245.png

JuhiPoddar_1-1729767147535.png

"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