I want to update a "Resolved Date" field on a table.

Sathwik1
Tera Expert

In a table "A" there are two fields., namely Field A, Field B.

 

Field A = State

Field B = Resolved Date

 

-> If STATE changes to "Resolved" then I need to update the RESOLVED DATE as current date/time.

 

I want to achieve it through "Function field" instead of using Business rule or UI Policy or something..

 

Can someone please help on this ? @Ankur Bawiskar 

1 ACCEPTED SOLUTION

@Sathwik1 

calculated field calculate every time a row is read.

So if you open incident list and it has 100 rows then the calculated field calculation will be performed 100 times.

I won't recommend doing this.

Since you just want to store then why not use before update business rule and store the current time in custom field.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@Sathwik1 

function field is used during reporting to show data on the fly rather than storing in some field.

what's your requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

We had one custom table, in which there are two fields named as State and Published date..

If State is changed to Publish then I want to update Publish date using GlideDateTime..

and here I don't want to use Business rule/UI Policy., just want to check if there is any other possiblity that I could update it easily.

@Ankur Bawiskar 

@Sathwik1

if not business rule then please use calculated field.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

NagaChandaE
Kilo Sage

HI @Sathwik1 

The functional field does not store value in database instead use the calculated value .

here is my solution Screenshot 2025-02-14 at 7.45.47 PM.png

 

 

 

(function calculatedFieldValue(current) {

if (current.u_resolved_date_time == "" && current.state == 6 ) { // Set resolved time if empty
    answer = new GlideDateTime();
} else if (current.state == 2) { // 2 is 'In Progress', clear the field
    answer = '';
} else {
    answer = current.resolved_time; // Retain previous value otherwise
}


	return answer;  // return the calculated value

})(current);

 

 

 

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Naga Chandan